-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.py
35 lines (26 loc) · 1.07 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import sqlite3
DEFAULT_DB = os.path.abspath(os.path.dirname(__file__) + './notice.db')
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
def get_cursor(db=DEFAULT_DB):
conn = sqlite3.connect(db)
conn.row_factory = dict_factory
conn.isolation_level = None
return conn.cursor()
def _create_tables():
c = get_cursor()
# 公告表
c.execute(
'CREATE TABLE if not exists notice (id integer primary key autoincrement,title varchar,published_at timestamp,source varchar,url text,status varchar,created_at timestamp,updated_at timestamp)')
# 公告详情表
c.execute(
'CREATE TABLE if not exists notice_detail (id integer primary key autoincrement,notice_id integer, raw_html text, content text)')
# 物资需求表(暂时没有用到)
c.execute(
'CREATE TABLE if not exists notice_demand (id integer primary key autoincrement,notice_id integer, item_name varchar,remark text)')
if __name__ == '__main__':
_create_tables()