本文整理汇总了Python中mapper.Mapper.has_statid方法的典型用法代码示例。如果您正苦于以下问题:Python Mapper.has_statid方法的具体用法?Python Mapper.has_statid怎么用?Python Mapper.has_statid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapper.Mapper
的用法示例。
在下文中一共展示了Mapper.has_statid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cards_to_database
# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import has_statid [as 别名]
def cards_to_database(database, cards_file):
"""
put data in cards_file into database.
"""
mapper = Mapper(configuration.map_file)
conn = sqlite3.connect(database)
cursor = conn.cursor()
cursor.execute("DROP TABLE IF EXISTS cards")
cursor.execute("""
CREATE TABLE IF NOT EXISTS cards
(posid TEXT,
time INTEGER,
statid TEXT)
""")
cursor.execute("CREATE INDEX time_index ON cards(time)")
cursor.execute("CREATE INDEX statid_index ON cards(statid)")
cursor.execute("CREATE INDEX posid_index ON cards(posid)")
with open(cards_file, 'r') as reader:
for line in reader:
parts = line.strip().split(',')
assert len(parts) == 15
if not mapper.has_statid(parts[9]):
continue
if parts[5].count(':') == 1:
parts[5] = parts[5] + ":00"
parts[5] = datetime.strptime(parts[5], "%Y/%m/%d %H:%M:%S")
parts[5] = calendar.timegm(parts[5].utctimetuple())
cursor.execute("INSERT INTO cards VALUES (?, ?, ?)",
(parts[3], parts[5], parts[9]))
cursor.close()
conn.commit()
conn.close()