-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb_init.py
More file actions
executable file
·55 lines (42 loc) · 1.24 KB
/
db_init.py
File metadata and controls
executable file
·55 lines (42 loc) · 1.24 KB
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
#!/usr/bin/env python3
import os
import sqlite3
def set_wal_mode(db_path):
conn = sqlite3.connect(db_path)
conn.execute("PRAGMA journal_mode=WAL")
conn.close()
def db_init_users():
db_path = "db_users.sqlite"
users = [("admin", "SuperSecret"), ("elliot", "123123123"), ("tim", "12345678")]
set_wal_mode(db_path)
conn = sqlite3.connect(db_path)
c = conn.cursor()
c.execute(
"CREATE TABLE users (username text, password text, failures int, mfa_enabled int, mfa_secret text)"
)
for u, p in users:
c.execute(
"INSERT INTO users (username, password, failures, mfa_enabled, mfa_secret) VALUES ('%s', '%s', '%d', '%d', '%s')"
% (u, p, 0, 0, "")
)
conn.commit()
conn.close()
def db_init_posts():
db_path = "db_posts.sqlite"
set_wal_mode(db_path)
conn = sqlite3.connect(db_path)
c = conn.cursor()
c.execute("CREATE TABLE posts (date date, username text, text text)")
conn.commit()
conn.close()
if __name__ == "__main__":
try:
os.remove("db_users.sqlite")
except FileNotFoundError:
pass
try:
os.remove("db_posts.sqlite")
except FileNotFoundError:
pass
db_init_users()
db_init_posts()