本文整理汇总了Python中tinydb.TinyDB.close方法的典型用法代码示例。如果您正苦于以下问题:Python TinyDB.close方法的具体用法?Python TinyDB.close怎么用?Python TinyDB.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinydb.TinyDB
的用法示例。
在下文中一共展示了TinyDB.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_prediction_cache
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def check_prediction_cache(
region_id,
type_id,
cache_path=CACHE_PATH,
db_filename='prophet.json'
):
"""check tinyDB for cached predictions
Args:
region_id (int): EVE Online region ID
type_id (int): EVE Online type ID
cache_path (str): path to caches
db_filename (str): name of tinydb
Returns:
pandas.DataFrame: cached prediction
"""
utc_today = datetime.utcnow().strftime('%Y-%m-%d')
prediction_db = TinyDB(path.join(cache_path, db_filename))
raw_data = prediction_db.search(
(Query().cache_date == utc_today) &
(Query().region_id == region_id) &
(Query().type_id == type_id)
)
prediction_db.close()
if raw_data:
panda_data = pd.read_json(raw_data[0]['prediction'])
return panda_data
else:
return None
示例2: test_write_first_cache
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def test_write_first_cache(self):
"""test write behavior on first pass (cache-buster mode)"""
self.test_clear_existing_cache() #blowup existing cache again
dummy_data = forecast_utils.parse_emd_data(DEMO_DATA['result'])
forecast_utils.write_prediction_cache(
self.region_id,
self.type_id,
dummy_data,
cache_path=self.cache_path
)
assert path.isfile(self.cache_filepath)
tdb = TinyDB(self.cache_filepath)
data = tdb.all()[0]
keys_list = [
'cache_date',
'region_id',
'type_id',
'lastWrite',
'prediction'
]
assert set(keys_list) == set(data.keys())
dummy_str_data = dummy_data.to_json(
date_format='iso',
orient='records'
)
cached_data = pd.read_json(data['prediction'])
assert data['prediction'] == dummy_str_data
tdb.close()
示例3: download
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def download(name,force=False):
db=TinyDB(path_db_)
temp = Query()
data=requests.get("https://raw.githubusercontent.com/PyThaiNLP/pythainlp-corpus/master/db.json")
data_json=data.json()
if name in list(data_json.keys()):
temp_name=data_json[name]
print("Download : "+name)
if len(db.search(temp.name==name))==0:
print(name+" "+temp_name['version'])
download_(temp_name['download'],temp_name['file_name'])
db.insert({'name': name, 'version': temp_name['version'],'file':temp_name['file_name']})
else:
if len(db.search(temp.name==name and temp.version==temp_name['version']))==0:
print("have update")
print("from "+name+" "+db.search(temp.name==name)[0]['version']+" update to "+name+" "+temp_name['version'])
yes_no="y"
if force==False:
yes_no=str(input("y or n : ")).lower()
if "y"==yes_no:
download_(temp_name['download'],temp_name['file_name'])
db.update({'version':temp_name['version']},temp.name==name)
else:
print("re-download")
print("from "+name+" "+db.search(temp.name==name)[0]['version']+" update to "+name+" "+temp_name['version'])
yes_no="y"
if force==False:
yes_no=str(input("y or n : ")).lower()
if "y"==yes_no:
download_(temp_name['download'],temp_name['file_name'])
db.update({'version':temp_name['version']},temp.name==name)
db.close()
示例4: index
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def index():
form = SearchForm()
query = request.args.get('query', '').strip()
db = TinyDB(recipyGui.config.get('tinydb'))
if not query:
runs = db.all()
else:
# Search run outputs using the query string
runs = db.search(
where('outputs').any(lambda x: listsearch(query, x)) |
where('inputs').any(lambda x: listsearch(query, x)) |
where('script').search(query) |
where('notes').search(query) |
where('unique_id').search(query))
runs = sorted(runs, key = lambda x: parse(x['date'].replace('{TinyDate}:', '')) if x['date'] is not None else x['eid'], reverse=True)
run_ids = []
for run in runs:
if 'notes' in run.keys():
run['notes'] = str(escape(run['notes']))
run_ids.append(run.eid)
db.close()
return render_template('list.html', runs=runs, query=query, form=form,
run_ids=str(run_ids),
dbfile=recipyGui.config.get('tinydb'))
示例5: log_output
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def log_output(filename, source):
filename = os.path.abspath(filename)
if option(CONFIG, 'general', 'debug'):
print("Output to %s using %s" % (filename, source))
#Update object in DB
db = TinyDB(DBFILE)
db.update(append("outputs", filename), eids=[RUN_ID])
db.close()
示例6: write
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def write(message, args):
# message.reply('I can understand hi or HI!')
# react with thumb up emoji
#message.react('+1')
db = TinyDB('db.json')
db.insert({'value': args});
print args
db.close()
示例7: get_file
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def get_file(name):
db=TinyDB(path_db_)
temp = Query()
if len(db.search(temp.name==name))>0:
path= get_path_data(db.search(temp.name==name)[0]['file'])
db.close()
if not os.path.exists(path):
download(name)
return path
示例8: get_genres
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
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)
示例9: api
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def api():
db = TinyDB(DB_FILENAME)
results = db.search((Query().hidden == False) | (Query().starred == True))
db.close()
for result in results:
result['eid'] = result.eid
result['url'] = url_for('goto', eid=result.eid)
results.sort(key=lambda r: r['created_at'])
return json.dumps(results)
示例10: test_gc
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def test_gc(tmpdir):
# See https://github.com/msiemens/tinydb/issues/92
path = str(tmpdir.join('db.json'))
db = TinyDB(path)
table = db.table('foo')
table.insert({'something': 'else'})
table.insert({'int': 13})
assert len(table.search(where('int') == 13)) == 1
assert table.all() == [{'something': 'else'}, {'int': 13}]
db.close()
示例11: patched_modules
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def patched_modules():
db = TinyDB(recipyGui.config.get('tinydb'))
modules = db.table('patches').all()
db.close()
form = SearchForm()
return render_template('patched_modules.html', form=form,
active_page='patched_modules', modules=modules,
dbfile=recipyGui.config.get('tinydb'))
示例12: runs2json
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def runs2json():
run_ids = literal_eval(request.form['run_ids'])
db = TinyDB(recipyGui.config.get('tinydb'))
runs = [db.get(eid=run_id) for run_id in run_ids]
db.close()
response = make_response(dumps(runs, indent=2, sort_keys=True))
response.headers['content-type'] = 'application/json'
response.headers['Content-Disposition'] = 'attachment; filename=runs.json'
return response
示例13: hide_all
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def hide_all():
db = TinyDB(DB_FILENAME)
eids = [
r.eid for r in db.search(
(Query().hidden == False) & (Query().starred == False)
)
]
db.update({'hidden': True}, eids=eids)
db.close()
return 'OK'
示例14: TinyDBConvertor
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
class TinyDBConvertor(object):
def __init__(self, collection_name, db_name, db_path=LOCAL_DIR):
self.local_db_fullpath = os.path.join(db_path, db_name)
self.local_db = TinyDB(self.local_db_fullpath)
self.collection_name = collection_name
def reload(self):
self.local_db.close()
self.local_db = TinyDB(self.local_db_fullpath)
def find(self):
self.reload()
query = Query()
resp = self.local_db.search(query.type == self.collection_name)
self.local_db.close()
return resp
def find_one(self, entry):
self.reload()
query = Query()
resp = self.local_db.search((query.type == self.collection_name) &
(query.fqu == entry['fqu']))
self.local_db.close()
if len(resp) == 0:
return None
else:
return resp[0]
def save(self, new_entry):
self.reload()
new_entry['type'] = self.collection_name
resp = self.local_db.insert(new_entry)
self.local_db.close()
return resp
def remove(self, entry):
self.reload()
query = Query()
resp = self.local_db.remove((query.type == self.collection_name) &
(query.fqu == entry['fqu']))
self.local_db.close()
return resp
示例15: annotate
# 需要导入模块: from tinydb import TinyDB [as 别名]
# 或者: from tinydb.TinyDB import close [as 别名]
def annotate():
notes = request.form['notes']
run_id = int(request.form['run_id'])
query = request.args.get('query', '')
db = TinyDB(recipyGui.config.get('tinydb'))
db.update({'notes': notes}, eids=[run_id])
db.close()
return redirect(url_for('run_details', id=run_id, query=query))