-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.py
57 lines (45 loc) · 1.26 KB
/
users.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
import sqlite3
def initialize(database):
conn = sqlite3.connect(database)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS TwitterPublicKey
(
TwitterId TEXT PRIMARY KEY,
PublicKey TEXT NOT NULL
);
''')
conn.commit()
conn.close()
def twitter_public_keys_select(database, twitter_user_id):
conn = sqlite3.connect(database)
cursor = conn.cursor()
cursor.execute('''
SELECT PublicKey
FROM TwitterPublicKey
WHERE TwitterId=?
''', (twitter_user_id,))
select_result = cursor.fetchone()
conn.close()
result = {
'twitterUserId': twitter_user_id
}
if select_result:
(public_key,) = select_result
result['publicKey'] = public_key
return result
def twitter_public_keys_insert_or_replace(database, twitter_user_id, public_key):
conn = sqlite3.connect(database)
cursor = conn.cursor()
cursor.execute('''
INSERT OR REPLACE
INTO TwitterPublicKey(TwitterId, PublicKey)
VALUES(?,?)
''', (twitter_user_id, public_key))
conn.commit()
conn.close()
result = {
'twitterUserId': twitter_user_id,
'publicKey': public_key
}
return result