本文整理汇总了Python中sqlitedict.SqliteDict.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python SqliteDict.iteritems方法的具体用法?Python SqliteDict.iteritems怎么用?Python SqliteDict.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlitedict.SqliteDict
的用法示例。
在下文中一共展示了SqliteDict.iteritems方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scribe
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import iteritems [as 别名]
class Scribe(object):
def __init__(self, location, table_name, exp_name):
filename = "{}/scribe.sqlite".format(location)
self.book = SqliteDict(filename, autocommit=True, tablename=table_name)
unique_id = datetime.now().strftime("date_%m.%d_time_%H.%M")
self.exp_name = exp_name+"_"+unique_id
self.observation_index = 0
def record(self, value, type="general"):
key = "{}; {}; {}".format(self.exp_name, self.observation_index, type)
self.book[key] = value
self.observation_index += 1
observe = record #sometimes i forget which
def lookup(self, type=None, exp_name=None, ret_sorted=False, strip_keys=False):
type_func = lambda *args: True
name_func = lambda *args: True
if type:
type_func = lambda x: x[2] == type
if exp_name:
name_func = lambda x: exp_name in x[0]
key_func = lambda x: type_func(x) and name_func(x)
unpack = lambda x: [f(x.strip()) for f,x in zip([str,int,str],x.split(";"))]
items = {k:v for k,v in self.book.iteritems() if key_func(unpack(k))}
if ret_sorted:
return self.sort_results(items, strip_keys)
return items
def sort_results(self, result_dict, only_val_return=False):
unpack = lambda x: [f(x.strip()) for f,x in zip([str,int,str],x.split(";"))]
ranker = lambda x: unpack(x[0])[1]
sorted_items = sorted(result_dict.items(), key=ranker)
if only_val_return:
return [v for k,v in sorted_items]
return sorted_items
def close(self):
self.book.close()
示例2: icon
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import iteritems [as 别名]
ICON_FONT_FILE = 'pifile.ttf'
ICON_FONT_JSON = 'config.json'
ICONS = icon(ICON_FONT_JSON, ICON_FONT_FILE)
##################################
# SCREEN BANNER VARIABLES
###################################
LOADING_MESSEGES = []
TREKNOBABBLE = 'treknobabble.tbdb'
_TREKNOBABBLE = os.path.join('resources/', TREKNOBABBLE)
tb_db = SqliteDict(_TREKNOBABBLE)
# for item in dict_db.iteritems():
# pprint(item)
for key, value in tb_db.iteritems():
LOADING_MESSEGES.append(value)
# return_event = pygame.event.Event(RETURN_EVENT)
# Dict of events that are accessible to screens
piscreenevents = {
"button": TFTBUTTONCLICK,
"update": UPDATESCREEN,
"nextscreen": NEXTSCREEN,
"toggle_fps": TOGGLE_FPS_EVENT,
}
示例3: get_tb
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import iteritems [as 别名]
myset = []
for link in soup.find_all('h1'):
tmp = link.get_text()
string = tmp[5:-3]
myset.append(string)
if myset[0] not in dict_db.iterkeys():
dict_db[myset[0]] = myset[1]
unique += 1
else:
print "Duplicate"
duplicates += 1
treknobabble.append(failure)
# get_tb()
for item in dict_db.iteritems():
pprint(item)
print len(dict_db)
dict_db.close()
# print "Dups: " + str(duplicates)
# f = open('treknobable.txt', 'w')
# f.write(x.get_string(sortby="Timestamp"))
# for thing in treknobabble:
# pprint(thing)
# for key in thing:
# f.write('\n' + '----------\n')
# f.write(key + '\n')
# f.write(thing[key])
示例4: tiny_db
# 需要导入模块: from sqlitedict import SqliteDict [as 别名]
# 或者: from sqlitedict.SqliteDict import iteritems [as 别名]
class tiny_db():
def __init__(self):
self.debug = True
self.dict_db = SqliteDict('./racks.sqlite', autocommit=True)
self.days_to_keep = 5
self._define_mem_db()
# SET UP DATABASE VARIABLES
self.row_height = DATABASE_SETTINGS['rows']
self.column_width = DATABASE_SETTINGS['columns']
self.get_last_filed()
self.rack_day = self._today()
self.next = {}
self._today()
self.next_location()
self._db_info()
if self.last_filed is None:
try:
self._convert_to_sqlitedb()
except:
print "Database is Empty"
# @profile
def _define_mem_db(self):
self.mem_db = []
for item in self.dict_db.iteritems():
self.mem_db.append(item[1])
# @profile
def _db_info(self):
if len(self.mem_db) > 0:
x = PrettyTable([" ", "size"])
x.add_row(["DB Size", len(self.dict_db)])
x = PrettyTable(["stats", "accn", "Date", "Timestamp"])
# pprint(self.last_filed)
readable = self._conv_timestamp(self.last_filed['time'])
x.add_row(["Last",
self.last_filed['accn'],
readable,
self.last_filed['time']])
first_filed = self.get_first_filed()
other_readable = self._conv_timestamp(first_filed['time'])
x.add_row(["First",
first_filed['accn'],
other_readable,
first_filed['time']])
# print x
return x
def _list_size(self):
size = {'memory': len(self.mem_db), 'disk': len(self.dict_db)}
return size
def _print_database(self):
if len(self.mem_db) < 2:
return none
x = PrettyTable(["Accn", "Rack", "Position", "Time", "Timestamp"])
# x.padding_width = 1
for item in self.mem_db:
x.add_row(self._make_entry_row(item))
# print x.get_string(sortby="Timestamp")
f = open('_database_info.txt', 'w')
f.write(x.get_string(sortby="Timestamp"))
f.write(self._db_info().get_string())
f.close()
print x.get_string(fields=["Accn", "Rack", "Position"])
def _make_entry_row(self, item):
readable = self._conv_timestamp(item['time'])
# print item['row']
x = [item['accn'],
item['rackDay'] + ' ' + str(item['rack']),
ROWS[str(item['row'])] + ' ' + str(item['column']),
readable,
item['time']]
return x
def _conv_timestamp(self, ts):
dt = datetime.datetime.fromtimestamp(float(ts))
return dt.strftime("%H:%M - %m.%d.%Y")
def _today(self):
self.purge_date = int(
mktime(
(datetime.date.today() -
datetime.timedelta(
self.days_to_keep)).timetuple()))
return strftime('%a', localtime(time()))
# @profile
def file_accn(self, accn):
insert = {
'accn': accn,
'rack': self.next['rack'],
'rackDay': self.next['rackDay'],
'column': self.next['column'],
'row': self.next['row'],
'time': str(time())
}
self.mem_db.append(insert)
#.........这里部分代码省略.........