本文整理汇总了Python中tinydb.TinyDB类的典型用法代码示例。如果您正苦于以下问题:Python TinyDB类的具体用法?Python TinyDB怎么用?Python TinyDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TinyDB类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: update_statistic
def update_statistic():
db = TinyDB("data/db.json")
rows = db.all()
rows.sort(key=lambda x: int(x['rid']), reverse=True)
levels = {1: [], 2: [], 3: []}
for row in rows:
levels[row['level']].append(row)
out = []
header = '|%-35s|%-40s|%-6s|%-10s|%5s|%10s|' % ("round", "problem", "solved", "ave_pts",
"rate", "submission")
for k, v in levels.items():
out.append('# LEVEL %d' % k)
out.append('-' * len(header))
out.append(header)
out.append('-' * len(header))
v.sort(key=lambda x: difficulty(x), reverse=True)
for i in v:
out.append('|%-35s|%-40s|%-6s|%-10.2lf|%-4.3lf|%10s|' % (i['round'], i['name'], i['solved'],
i['average_pts'], i['correct_rate'], i['submissions']))
out.append('*' * len(header))
with open("data/statistic.txt", 'w') as f:
for i in out:
f.write(i + '\n')
print '>>>> data/statistic.txt has been updated.'
开发者ID:eggeek,项目名称:topcoder,代码行数:25,代码来源:update.py
示例2: AddUser
def AddUser(self, username, chatid):
my_pokemon = [0] * 152 # Matching arr index to pokemon index (0 is disregarded)
db = TinyDB('users.json')
db.insert({'username': username, 'chatid': chatid, 'pokemon': my_pokemon})
pass # RETURN: check bool
开发者ID:bcc5160,项目名称:PokeBot,代码行数:7,代码来源:tinydb_interface.py
示例3: save_customer
def save_customer(self, customer):
if not self.validate(customer):
return None
db = TinyDB('db/db.json')
return db.insert(customer)
开发者ID:khlumzeemee,项目名称:3dprinter,代码行数:7,代码来源:ApplicationMVC.py
示例4: test_serialisation_of_numpy_ndarray
def test_serialisation_of_numpy_ndarray(tmpdir):
from sacred.observers.tinydb_hashfs import NdArraySerializer
from tinydb_serialization import SerializationMiddleware
import numpy as np
# Setup Serialisation object for non list/dict objects
serialization_store = SerializationMiddleware()
serialization_store.register_serializer(NdArraySerializer(), 'TinyArray')
db = TinyDB(os.path.join(tmpdir.strpath, 'metadata.json'),
storage=serialization_store)
eye_mat = np.eye(3)
ones_array = np.ones(5)
document = {
'foo': 'bar',
'some_array': eye_mat,
'nested': {
'ones': ones_array
}
}
db.insert(document)
returned_doc = db.all()[0]
assert returned_doc['foo'] == 'bar'
assert (returned_doc['some_array'] == eye_mat).all()
assert (returned_doc['nested']['ones'] == ones_array).all()
开发者ID:IDSIA,项目名称:sacred,代码行数:29,代码来源:test_tinydb_observer.py
示例5: check_prediction_cache
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
开发者ID:EVEprosper,项目名称:ProsperAPI,代码行数:35,代码来源:forecast_utils.py
示例6: insert_test
def insert_test(db_file='db.json'):
db = TinyDB(db_file)
db.insert({
'name': 'Aman Verma',
'items': 1,
'contact': 7890701597
})
开发者ID:santosh1207,项目名称:TinyDB,代码行数:7,代码来源:inserting.py
示例7: __init__
def __init__(self, path):
root_dir = os.path.abspath(path)
if not os.path.exists(root_dir):
raise IOError('Path does not exist: %s' % path)
fs = HashFS(os.path.join(root_dir, 'hashfs'), depth=3,
width=2, algorithm='md5')
# Setup Serialisation for non list/dict objects
serialization_store = SerializationMiddleware()
serialization_store.register_serializer(DateTimeSerializer(),
'TinyDate')
serialization_store.register_serializer(FileSerializer(fs),
'TinyFile')
if opt.has_numpy:
serialization_store.register_serializer(NdArraySerializer(),
'TinyArray')
if opt.has_pandas:
serialization_store.register_serializer(DataFrameSerializer(),
'TinyDataFrame')
serialization_store.register_serializer(SeriesSerializer(),
'TinySeries')
db = TinyDB(os.path.join(root_dir, 'metadata.json'),
storage=serialization_store)
self.db = db
self.runs = db.table('runs')
self.fs = fs
开发者ID:elanmart,项目名称:sacred,代码行数:30,代码来源:tinydb_hashfs.py
示例8: test_serialisation_of_pandas_dataframe
def test_serialisation_of_pandas_dataframe(tmpdir):
from sacred.observers.tinydb_hashfs import (DataFrameSerializer,
SeriesSerializer)
from tinydb_serialization import SerializationMiddleware
import numpy as np
import pandas as pd
# Setup Serialisation object for non list/dict objects
serialization_store = SerializationMiddleware()
serialization_store.register_serializer(DataFrameSerializer(),
'TinyDataFrame')
serialization_store.register_serializer(SeriesSerializer(),
'TinySeries')
db = TinyDB(os.path.join(tmpdir.strpath, 'metadata.json'),
storage=serialization_store)
df = pd.DataFrame(np.eye(3), columns=list('ABC'))
series = pd.Series(np.ones(5))
document = {
'foo': 'bar',
'some_dataframe': df,
'nested': {
'ones': series
}
}
db.insert(document)
returned_doc = db.all()[0]
assert returned_doc['foo'] == 'bar'
assert (returned_doc['some_dataframe'] == df).all().all()
assert (returned_doc['nested']['ones'] == series).all()
开发者ID:IDSIA,项目名称:sacred,代码行数:35,代码来源:test_tinydb_observer.py
示例9: index
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'))
开发者ID:pablo-esteban,项目名称:recipy,代码行数:30,代码来源:views.py
示例10: test_json_readwrite
def test_json_readwrite(tmpdir):
"""
Regression test for issue #1
"""
path = str(tmpdir.join('test.db'))
# Create TinyDB instance
db = TinyDB(path, storage=JSONStorage)
item = {'name': 'A very long entry'}
item2 = {'name': 'A short one'}
get = lambda s: db.get(where('name') == s)
db.insert(item)
assert get('A very long entry') == item
db.remove(where('name') == 'A very long entry')
assert get('A very long entry') is None
db.insert(item2)
assert get('A short one') == item2
db.remove(where('name') == 'A short one')
assert get('A short one') is None
开发者ID:lordjabez,项目名称:tinydb,代码行数:25,代码来源:test_storages.py
示例11: dragon_greet
def dragon_greet():
print("_______________________________________________________________\n")
time = datetime.datetime.now().time()
global user_full_name
global user_prefix
global config_file
command = "getent passwd $LOGNAME | cut -d: -f5 | cut -d, -f1"
user_full_name = os.popen(command).read()
user_full_name = user_full_name[:-1] # .decode("utf8")
home = expanduser("~")
config_file = TinyDB(home + '/.dragonfire_config.json')
callme_config = config_file.search(Query().datatype == 'callme')
if callme_config:
user_prefix = callme_config[0]['title']
else:
gender_config = config_file.search(Query().datatype == 'gender')
if gender_config:
user_prefix = GENDER_PREFIX[gender_config[0]['gender']]
else:
gender = Classifier.gender(user_full_name.split(' ', 1)[0])
config_file.insert({'datatype': 'gender', 'gender': gender})
user_prefix = GENDER_PREFIX[gender]
if time < datetime.time(12):
time_of_day = "morning"
elif datetime.time(12) < time < datetime.time(18):
time_of_day = "afternoon"
else:
time_of_day = "evening"
userin.execute(["echo"], "To activate say 'Dragonfire!' or 'Wake Up!'")
userin.say(" ".join(["Good", time_of_day, user_prefix]))
开发者ID:igorstarki,项目名称:Dragonfire,代码行数:33,代码来源:__init__.py
示例12: __init__
class pcDB:
def __init__(self,table="default"):
#'/path/to/db.json'
path=''
self.table=table
self.db = TinyDB(path).table(table)
def insert(self,_dict):
'''
:return:
'''
self.db.insert(_dict)
# db.insert({'int': 1, 'char': 'a'})
# db.insert({'int': 1, 'char': 'b'})
pass
def getAll(self):
'''
not param just get all data
:return:
'''
return self.db.all()
#db.search()
pass
pass
#
# from tinydb.storages import JSONStorage
# from tinydb.middlewares import CachingMiddleware
# db = TinyDB('/path/to/db.json', storage=CachingMiddleware(JSONStorage))
开发者ID:guoyu07,项目名称:picture-compare,代码行数:27,代码来源:db.py
示例13: get_coffees
def get_coffees(active):
name = ''
name_link = ''
nav_links = []
description = ''
db = TinyDB('db/coffee.json')
coffee = db.all()
count = 0
coffee_id = 0
for i in coffee:
if active == -1 and count == 0:
nav_links.append(("/"+str(i['id']),"active",i['name']))
name = i['name']
description = i['description']
coffee_id = i['id']
name_link = '/'+str(i['id'])
elif active == -1 and count > 0:
nav_links.append(("/"+str(i['id']),"",i['name']))
elif active == i['id']:
nav_links.append(("/"+str(i['id']),"active",i['name']))
name = i['name']
description = i['description']
coffee_id = i['id']
name_link = '/'+str(i['id'])
else:
nav_links.append(("/"+str(i['id']),"",i['name']))
count = count+1
for i in nav_links:
print i
print name
print name_link
return nav_links, name, name_link, description, coffee_id
开发者ID:nvijay83,项目名称:philz,代码行数:33,代码来源:webapp.py
示例14: test_process
def test_process(tmpdir, capsys, side_effect, success):
db_fn = tmpdir.join('database.json')
log_dir = tmpdir.mkdir('log')
db = TinyDB(db_fn.strpath)
process_me = '/my/path/A12345'
accession_number = op.basename(process_me)
paths2process = {process_me: 42}
with patch('subprocess.Popen') as mocked_popen:
stdout = b"INFO: PROCESSING STARTS: {'just': 'a test'}"
mocked_popen_instance = mocked_popen.return_value
mocked_popen_instance.side_effect = side_effect
mocked_popen_instance.communicate.return_value = (stdout, )
# set return value for wait
mocked_popen_instance.wait.return_value = 1 - success
# mock also communicate to get the supposed stdout
process(paths2process, db, wait=-30, logdir=log_dir.strpath)
out, err = capsys.readouterr()
log_fn = log_dir.join(accession_number + '.log')
mocked_popen.assert_called_once()
assert log_fn.check()
assert log_fn.read() == stdout.decode('utf-8')
assert db_fn.check()
# dictionary should be empty
assert not paths2process
assert out == 'Time to process {0}\n'.format(process_me)
# check what we have in the database
Path = Query()
query = db.get(Path.input_path == process_me)
assert len(db) == 1
assert query
assert query['success'] == success
assert query['accession_number'] == op.basename(process_me)
assert query['just'] == 'a test'
开发者ID:cni-md,项目名称:heudiconv,代码行数:35,代码来源:test_monitor.py
示例15: setUp
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
开发者ID:Mester,项目名称:demo-day-vikings,代码行数:7,代码来源:test_utils.py
示例16: crawl
def crawl(sr=0, er=3):
archive = dict()
url = "https://community.topcoder.com/tc?module=ProblemArchive&sr=%d&er=%d" % (sr, er)
print "requesting seed page..."
r = requests.get(url)
html = h.unescape(r.content.decode('utf-8'))
doc = pq(html)
for i in doc('table.paddingTable2').eq(2).children()[3:]:
round_name = pq(i).children().eq(2).find('a').text()
sub_url = pq(i).children().eq(2).find('a').attr.href
if sub_url is not None:
rid = sub_url.split('rd=')[-1]
archive[round_name] = {'rid': rid, 'round': round_name}
db = TinyDB("data/db.json")
tot = len(archive.values())
cur = 0
prob_cnt = 0
for k in archive.values():
problems = crawl_round(k['rid'], k['round'])
print 'parse result:'
for p in problems:
for pk, pv in p.items():
print "%-15s: %s" % (pk, pv)
prob_cnt += 1
q = Query()
if not db.search(q.name == p['name']):
print '>>>>>>> insert problem: %s' % p['name']
db.insert(p)
print '-' * 10
cur += 1
print '*' * 10, 'finish', k['round'], ',tot rounds:', tot, 'cur round:', cur, 'round problems:', len(problems), '*' * 10
print 'done, total round: %d, total problems: %d' % (cur, prob_cnt)
开发者ID:eggeek,项目名称:topcoder,代码行数:32,代码来源:crawler.py
示例17: __init__
def __init__(self):
self.sentCache = {}
self.checkingThread = threading.Thread(target = self.startThread)
#self.checkingThread.daemon = True
self.keepChecking = True
self.config = Config()
if self.config.winning_streak:
self.winning_streak_messages = self.read_spree_file(self.config.winning_streak_file)
if self.config.losing_streak:
self.losing_streak_messages = self.read_spree_file(self.config.losing_streak_file)
# Debug purposes
self.printOutput = False
# Initializing the API
key = dotamatch.get_key() # Steam Dev Key (~/.steamapi)
try:
self.match_history = MatchHistory(key)
self.match_details = MatchDetails(key)
self.account_details = PlayerSummaries(key)
self.heroes = Heroes(key).heroes()
# ActualDB
db = TinyDB(self.config.db_path)
#db.purge()
#db.purge_tables()
self.matches_table = db.table('matches')
self.matches_info_table = db.table('matches_info')
except dotamatch.api.ApiError:
print u"Erro ao conectar à API."
开发者ID:leonardobsjr,项目名称:D2WBot,代码行数:32,代码来源:D2WBot_Utils.py
示例18: prelimsearchURLs
def prelimsearchURLs():
db = TinyDB('db.json')
prelimtable = db.table('prelimcasedetails')
cases = getAllSearchResults()
prelimtable.purge()
for idx, case in enumerate(cases):
prelimtable.insert({'caseid': case.caseid, 'casename': case.casename, 'prelimvideourl': case.videourl,'detailedVideoURL':'0'})
开发者ID:unni88,项目名称:texascscraper,代码行数:7,代码来源:test.py
示例19: is_vip
def is_vip(author):
vip_db = TinyDB("dbs/vips.json")
try:
vip_db.get(where("email") == author)
return True
except:
return False
开发者ID:fhebert-perkins,项目名称:helpdesk,代码行数:7,代码来源:maildaemon.py
示例20: test_write_first_cache
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()
开发者ID:EVEprosper,项目名称:ProsperAPI,代码行数:35,代码来源:test_forecast_utils.py
注:本文中的tinydb.TinyDB类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论