|
4 | 4 | import sqlite3 |
5 | 5 |
|
6 | 6 |
|
7 | | -def db_init_users(): |
| 7 | +def set_wal_mode(db_path): |
| 8 | + conn = sqlite3.connect(db_path) |
| 9 | + conn.execute("PRAGMA journal_mode=WAL") |
| 10 | + conn.close() |
8 | 11 |
|
9 | | - users = [ |
10 | | - ('admin', 'SuperSecret'), |
11 | | - ('elliot', '123123123'), |
12 | | - ('tim', '12345678') |
13 | | - ] |
14 | 12 |
|
15 | | - conn = sqlite3.connect('db_users.sqlite') |
| 13 | +def db_init_users(): |
| 14 | + db_path = "db_users.sqlite" |
| 15 | + users = [("admin", "SuperSecret"), ("elliot", "123123123"), ("tim", "12345678")] |
| 16 | + set_wal_mode(db_path) |
| 17 | + conn = sqlite3.connect(db_path) |
16 | 18 | c = conn.cursor() |
17 | | - c.execute("CREATE TABLE users (username text, password text, failures int, mfa_enabled int, mfa_secret text)") |
| 19 | + c.execute( |
| 20 | + "CREATE TABLE users (username text, password text, failures int, mfa_enabled int, mfa_secret text)" |
| 21 | + ) |
18 | 22 |
|
19 | | - for u,p in users: |
20 | | - c.execute("INSERT INTO users (username, password, failures, mfa_enabled, mfa_secret) VALUES ('%s', '%s', '%d', '%d', '%s')" %(u, p, 0, 0, '')) |
| 23 | + for u, p in users: |
| 24 | + c.execute( |
| 25 | + "INSERT INTO users (username, password, failures, mfa_enabled, mfa_secret) VALUES ('%s', '%s', '%d', '%d', '%s')" |
| 26 | + % (u, p, 0, 0, "") |
| 27 | + ) |
21 | 28 |
|
22 | 29 | conn.commit() |
23 | 30 | conn.close() |
24 | 31 |
|
25 | 32 |
|
26 | 33 | def db_init_posts(): |
27 | | - |
28 | | - conn = sqlite3.connect('db_posts.sqlite') |
| 34 | + db_path = "db_posts.sqlite" |
| 35 | + set_wal_mode(db_path) |
| 36 | + conn = sqlite3.connect(db_path) |
29 | 37 | c = conn.cursor() |
30 | 38 | c.execute("CREATE TABLE posts (date date, username text, text text)") |
31 | 39 |
|
32 | 40 | conn.commit() |
33 | 41 | conn.close() |
34 | 42 |
|
35 | 43 |
|
36 | | -if __name__ == '__main__': |
37 | | - |
| 44 | +if __name__ == "__main__": |
38 | 45 | try: |
39 | | - os.remove('db_users.sqlite') |
| 46 | + os.remove("db_users.sqlite") |
40 | 47 | except FileNotFoundError: |
41 | 48 | pass |
42 | 49 |
|
43 | 50 | try: |
44 | | - os.remove('db_posts.sqlite') |
| 51 | + os.remove("db_posts.sqlite") |
45 | 52 | except FileNotFoundError: |
46 | 53 | pass |
47 | | - |
48 | 54 | db_init_users() |
49 | 55 | db_init_posts() |
50 | | - |
|
0 commit comments