def test(): if os.path.exists(filename): os.remove(filename) mdb = MicroDB(filename, testpartition_keys) mdb.erase_all() mdb = MicroDB(filename, testpartition_keys) for d in test_data: mdb.upsert(d) mdb.save() mdb.pprint_all() mdb2 = MicroDB(filename, testpartition_keys) for d in mdb2.all(): print(d) mdb2.save_as_grid() mdb3 = MicroDB(filename, testpartition_keys) for d in mdb3.all(): print(d) mdb4 = MicroDB(filename, testpartition_keys) mdb4.upsert({ 'job': 'study', 'name': 'Bob', 'status': 'undone', 'extra-info': 'hogehoge' }) try: mdb4.save_as_grid() except Exception as e: print(e) mdb4.save() mdb4
def save_all_repos(): all_repos = get_all_repos() all_repos = trim_repos(all_repos) all_repos = exclude_no_thanks(all_repos) mdb = MicroDB(jsons_dir + 'repos.json', partition_keys=[ 'full_name', ]) for repo in all_repos: mdb.upsert(dictionary=repo) mdb.save()
def del_wrong_data(): mdb_gifs = MicroDB(jsons_dir + 'gifs.json', partition_keys=[ 'full_name', ]) del_fullnames = [] for d in mdb_gifs.all(): if isinstance(d['success'], str): del_fullnames.append(d) print(d) print(len(del_fullnames)) print(del_fullnames) for del_fullname in del_fullnames: key = mdb_gifs.gen_key(del_fullname) print(key) del mdb_gifs[key] mdb_gifs.save()