-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_utils.py
41 lines (33 loc) · 983 Bytes
/
db_utils.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
import sqlite3
con = sqlite3.connect('karani.db')
cur = con.cursor()
query = """
SELECT post_id, media FROM "main"."POSTS";
"""
# update_query = """
# UPDATE "main"."POSTS" set media =
# """
# res = cur.execute(query)
#
# for row in res.fetchall():
# post_id, media = row
# cur.execute(f"""UPDATE "main"."POSTS" set media = '{media}.jpg' where post_id = {post_id}""")
# con.commit()
#
# tagged_users_query = """
# SELECT * FROM TAGGED_USERS;
# """
#
# res = cur.execute(tagged_users_query)
#
# for row in res.fetchall():
# post_id, user_id = row
# cur.execute(f"""UPDATE "main"."TAGGED_USERS" set user_id = (SELECT id FROM USER ORDER BY RANDOM() LIMIT 1) where post_id = {post_id}""")
# con.commit()
# con.close()
res = cur.execute(query)
for row in res.fetchall():
post_id, media = row
cur.execute(f"""UPDATE POSTS set location = (SELECT id FROM LOCATIONS ORDER BY RANDOM() LIMIT 1) where post_id = {post_id}""")
con.commit()
con.close()