-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdb_init.py
125 lines (104 loc) · 3.95 KB
/
db_init.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
''' DB init '''
import sqlite3
import os
db_name = 'data.db3'
try:
os.remove(db_name)
except:
pass
conn = sqlite3.connect(db_name)
cur = conn.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS\
user(\
user_id INTEGER PRIMARY KEY AUTOINCREMENT,\
username VARCHAR(32) UNIQUE,\
password VARCHAR(32),\
njuid VARCHAR(20),\
user_type VARCHAR(32))')
cur.execute("INSERT INTO user VALUES (1000,'root','root','131220088','root')")
cur.execute("INSERT INTO user VALUES (1001, 'lxiange','lxiange','131220088','stu')")
cur.execute("CREATE TABLE article(\
article_id INTEGER PRIMARY KEY AUTOINCREMENT,\
title VARCHAR(512),\
author VARCHAR(100),\
content VARCHAR(1000000),\
date_ VARCHAR(100))")
cur.execute("INSERT INTO article \
VALUES (1000,'hello world','root','Hello! It is a test!','2016-01-08 23:57:32')")
cur.execute("CREATE TABLE announcement(\
announcement_id INTEGER PRIMARY KEY AUTOINCREMENT,\
title VARCHAR(512),\
author VARCHAR(100),\
content VARCHAR(1000000),\
date_ VARCHAR(100))")
cur.execute("INSERT INTO announcement \
VALUES (1000,'announcement title','root','Hello! It is a test!','2016-01-08 23:57:32')")
cur.execute("CREATE TABLE user_info (\
username VARCHAR(32),\
sex VARCHAR(16),\
email VARCHAR(128),\
truename VARCHAR(128),\
mobile VARCHAR(20),\
self_intro VARCHAR(100000))")
cur.execute("INSERT INTO user_info VALUES (?, ?, ?, ?, ?, ?)",
('root', 'male', 'root@root.com', '2009-11-1', '13425243343', 'hello world!'))
cur.execute("CREATE TABLE homework (\
homework_id INTEGER PRIMARY KEY AUTOINCREMENT,\
title VARCHAR(512),\
author VARCHAR(100),\
content VARCHAR(1000000),\
date_ VARCHAR(100),\
deadline VARCHAR(100))")
cur.execute("INSERT INTO homework VALUES (?, ?, ?, ?, ?, ?)",
(1000, 'eat shit', 'root', 'ffffffff', '2013-01-08 23:57:32', '2016-01-18 23:57:32'))
cur.execute("CREATE TABLE submission (\
submission_id INTEGER PRIMARY KEY AUTOINCREMENT,\
author VARCHAR(128),\
title VARCHAR(512),\
content VARCHAR(1000000),\
date_ VARCHAR(100),\
homework_id INTEGER,\
file_path VARCHAR(500),\
status VARCHAR(100))")
cur.execute("INSERT INTO submission VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(1000, 'root', 'first commit', 'this is the content', '2013-01-08 23:57:32', 1000, '/homework/1/111.rar', 'submitted'))
cur.execute("CREATE TABLE resource (\
resource_id INTEGER PRIMARY KEY AUTOINCREMENT,\
author VARCHAR(128),\
title VARCHAR(512),\
content VARCHAR(1000000),\
date_ VARCHAR(100),\
file_path VARCHAR(500))")
cur.execute("INSERT INTO resource VALUES (?, ?, ?, ?, ?, ?)",
(1000, 'root', 'first resource', 'this is the first resource', '2013-01-08 23:57:32', ''))
cur.execute("CREATE TABLE message (\
message_id INTEGER PRIMARY KEY AUTOINCREMENT,\
sender_name VARCHAR(128),\
receiver_name VARCHAR(128),\
title VARCHAR(256),\
content VARCHAR(220000),\
date_ VARCHAR(100))")
cur.execute("INSERT INTO message VALUES (?, ?, ?, ?, ?, ?)",
(1000, 'lxiange', 'root', '', 'fuck you', '2013-01-08 23:57:32'))
conn.commit()
conn.close()
try:
os.mkdir('data')
except:
pass
try:
os.mkdir('data/user_pic')
except:
pass
try:
os.mkdir('data/resource')
except:
pass
try:
os.mkdir('data/homework')
except:
pass
try:
os.mkdir('data/homework/hw_1000')
except:
pass