python类TinyDB()的实例源码

result_log.py 文件源码 项目:dontwi 作者: vocalodon 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def remove_summaries_by_eids(self, eids):
        f_name = self.items["result log"]["db_file"]
        with TinyDB(f_name) as db_entity:
            return db_entity.remove(eids=eids)
tynydb.py 文件源码 项目:sketal 作者: vk-brain 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self):
        """Adds self to messages and event's `data` field.
        Through this instance you can access TinyDB instance (data["tinydbproxy"].tinydb).
        This plugin should be included first!
        """

        super().__init__()

        self.tinydb = TinyDB(path=self.get_path("tinydb_database.json"), storage=CachingMiddleware(JSONStorage))
tinyrundb.py 文件源码 项目:linchpin 作者: CentOS-PaaS-SIG 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _opendb(self):
        self.middleware = CachingMiddleware(JSONStorage)
        self.middleware.WRITE_CACHE_SIZE = 500
        self.db = TinyDB(self.conn_str, storage=self.middleware,
                         default_table=self.default_table)
get_json.py 文件源码 项目:demo-day-vikings 作者: Mester 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def main():
    """Method to put it all together"""
    db = TinyDB(os.path.join(os.getcwd(), DATABASE_NAME))
    for sort_type in ["hot", "new", "top"]:
        logger.debug("Fetching url: {}".format(sort_type))
        json_data = get_json_from_subreddit(sort_type, 100)
        json_list = []
        for data in json_data:
            for post in data['data']['children']:
                if is_post_valid(post):
                    j = convert_post_to_json(post)
                    if j is not None:
                        insert_into_database(db, j)
utils.py 文件源码 项目:demo-day-vikings 作者: Mester 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_genres(database_name):
    """Utility method to get all the genres as a set"""
    db = TinyDB(os.path.join(os.getcwd(), database_name))
    all_genres = { song['genre'] for song in db.all() }
    specific_genres = set()
    for genre in all_genres:
        specific_genres = specific_genres.union(set(genre.strip().split('/')))
    db.close()
    return _strip_spaces(specific_genres)
utils.py 文件源码 项目:demo-day-vikings 作者: Mester 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_total_songs(database_name):
    """Utility Method to get the total number of songs in the database"""
    db = TinyDB(os.path.join(os.getcwd(), database_name))
    total_length = len(db.all())
    db.close()
    return total_length
test_utils.py 文件源码 项目:demo-day-vikings 作者: Mester 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def setUp(self):
        with open(os.path.join(BASE_DIR, 'tests', 'fixtures', 'test.json')) as f:
            self.j = json.load(f)
        self.database_name = os.path.join(os.getcwd(), 'test.db')
        db = TinyDB(self.database_name)
        db.insert_multiple(self.j)
        db.close
database.py 文件源码 项目:ask_data_science 作者: AngelaVC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, page=None, db=None):
        self.db = TinyDB(db)
        self.page = page
        # TODO need to do some check that database is well formed
        # TODO and that the page is a well-formed WebPage object

        self.db.insert({
                'url': self.page.link,
                'title': self.page.title,
                'text': self.page.text,
                'links': self.page.links})
generate.py 文件源码 项目:ask_data_science 作者: AngelaVC 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def gatherText(self):
        ''' Takes a TinyDB with a "text" field and combines all the text into
        a one list of texts
        '''
        all_text = ""
        for item in self.db:
            all_text = all_text + " " + clean_text(item['text'])
        self.text = all_text
tinydb.py 文件源码 项目:telebot 作者: DronMDF 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def set(self, name, value):
        db = TinyDB(self.filename)
        db.upsert({'name': name, 'value': value}, where('name') == name)
tinydb.py 文件源码 项目:telebot 作者: DronMDF 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get(self, name, default=None):
        db = TinyDB(self.filename)
        item = db.get(where('name') == name)
        if item is not None:
            return item.get('value', default)
        return default
public_sharing_manager.py 文件源码 项目:EasyStorj 作者: lakewik 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        self.node_details_content = None
        self.public_files_db = TinyDB('public_files.json')
        self.table = self.public_files_db.table('public_files')
playlist_manager.py 文件源码 项目:EasyStorj 作者: lakewik 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self):
        self.ownstorj_playlists_db = TinyDB('ownstorj_playlists.json')
        self.playlists_table = self.ownstorj_playlists_db.table('playlists')
        self.tracks_table = self.ownstorj_playlists_db.table('tracks')
base.py 文件源码 项目:simple-environment-monitor-system 作者: diegorubin 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, **attributes):
        self.__dict__ = attributes
        self.db = TinyDB(TINY_DB_PATH)
        self.table = self.db.table(self.__class__.__name__)
logs.py 文件源码 项目:G-Scout 作者: nccgroup 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def list_log_services():
    projectId = TinyDB('projects.json').table("Project").all()
    resp, content = storage.get().authorize(Http()).request("https://logging.googleapis.com/v1beta3/projects/" + projectId + "/logServices","GET")
    return [service['name'] for service in json.loads(content)['logServices']]
instance_groups.py 文件源码 项目:G-Scout 作者: nccgroup 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def insert_templates():
    projectId = TinyDB('projects.json').table("Project").all()
    request = instanceTemplates.list(project=projectId)
        try:
            while request is not None:
                response = request.execute()
                for instanceTemplate in response['items']:
                    template_table.insert(instanceTemplate)
                request = instanceTemplates.list_next(previous_request=request, previous_response=response)
        except KeyError:
            pass
instance_groups.py 文件源码 项目:G-Scout 作者: nccgroup 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def insert_instance_groups():
    projectId = TinyDB('projects.json').table("Project").all()
    for zone in get_zones():
        request = instanceGroups.list(project=projectId, zone=zone)
        try:
            while request is not None:
                response = request.execute()
                for instanceGroup in response['items']:
                    group_table.insert(instanceGroup)
                request = instanceGroups.list_next(previous_request=request, previous_response=response)
        except KeyError:
            pass
instance_groups.py 文件源码 项目:G-Scout 作者: nccgroup 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_zones():
    projectId = TinyDB('projects.json').table("Project").all()
    results = []
    request = zones.list(project=projectId)
    response = request.execute()['items']
    for result in response:
        results.append(result['name'])
    return results
phelper.py 文件源码 项目:aws-pricing-tools 作者: concurrencylabs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def loadDBs(service, indexFiles):

    dBs = {}
    datadir = get_data_directory(service)
    indexMetadata = getIndexMetadata(service)

    #Files in Lambda can only be created in the /tmp filesystem - If it doesn't exist, create it.
    lambdaFileSystem = '/tmp/'+service+'/data'
    if not os.path.exists(lambdaFileSystem):
      os.makedirs(lambdaFileSystem)

    for i in indexFiles:
      db = tinydb.TinyDB(lambdaFileSystem+'/'+i+'.json')
      #TODO: remove circular dependency from utils, so I can use the method get_index_file_name
      #TODO: initial tests show that is faster (by a few milliseconds) to populate the file from scratch). See if I should load from scratch all the time
      #TODO:Create a file that is an index of those files that have been generated, so the code knows which files to look for and avoid creating unnecesary empty .json files
      if len(db) == 0:
        try:
          with open(datadir+i+'.csv', 'rb') as csvfile:
              pricelist = csv.DictReader(csvfile, delimiter=',', quotechar='"')
              db.insert_multiple(pricelist)
        except IOError:
          pass
      dBs[i]=db

    return dBs, indexMetadata
househunt.py 文件源码 项目:househunt 作者: althor880 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self):
        self.db = TinyDB(os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__)), ListCache.DB_FILE))


问题


面经


文章

微信
公众号

扫码关注公众号