-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB_Constructor.py
More file actions
53 lines (50 loc) · 1.54 KB
/
Copy pathDB_Constructor.py
File metadata and controls
53 lines (50 loc) · 1.54 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
import sqlite3
"""
[
{
"action": "genesis",
"hash": "0"
},
{
"action": "create_acc",
"hash": "c78175a71196020526c49051f56f6aafe80024dd3acc2e597aecf67b66cb29a7",
"name": "Akhilesh Wagh",
"token": "29d7bf58940b9ad38d66cc53cb41c2b0"
},
{
"action": "create_acc",
"hash": "e5dd5e0a082e124833d440c09b4e26e3a8ab56d3ead63535ae4ec637ffb14462",
"name": "abc",
"token": "a82a9a796ee35503ad5966c20febc4ea"
},
{
"action": "create_acc",
"hash": "24717b616a21b4a6f860a1cb807ef7d7d4bed60211a81995707de434a0ba6189",
"name": "Akhilesh",
"token": "f04f5e3448a8641d0c6e427948b15560"
}
]
"""
def construct_db(BLOCKCHAIN, update=False):
conn = sqlite3.connect('smn.db')
c = conn.cursor()
if not update:
c.execute('''
CREATE TABLE IF NOT EXISTS users (
token TEXT PRIMARY KEY,
name TEXT NOT NULL,
reputation INTEGER NOT NULL
)
''')
c.execute('''
CREATE TABLE IF NOT EXISTS posts (
postID INTEGER PRIMARY KEY AUTOINCREMENT,
token TEXT NOT NULL,
CID INTEGER NOT NULL,
FOREIGN KEY (token) REFERENCES users(token)
)
''')
conn.commit()
conn.close()
if __name__ == "__main__":
construct_db([{'hash': '4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945', 'action': 'initiate'}, {'hash': 'c26afa923135ba44edb2a8daaeeab30b68315c30a1913c835e0569d223e51a1b', 'action': 'create_acc', 'name': 'Akhilesh', 'token': '4bb6c3337d11a5ab1862d0a3da31e3b9'}])