-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsqlitetopgsql.py
91 lines (57 loc) · 2.26 KB
/
sqlitetopgsql.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# convert db.sqlite3 to csv
import sqlite3
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
c.execute("SELECT medicine_name, medicine_description, medicine_image, medicine_price FROM vedassist_medicine")
medicine_details = []
already_added = ['Ahiphenasava', 'Amritarishta', 'Aragwadharishtam', 'Angoorasava', 'Abhayarishta']
row = c.fetchall()
for row in row:
medicine_details.append(
{
"medicine_name": row[0],
"medicine_description": row[1],
"medicine_image": row[2],
"medicine_price": row[3]
}
) if row[0] not in already_added else None
print(medicine_details)
print(len(medicine_details))
conn.close()
# connect to postgresql db on vercel
import psycopg2
import os
DATABASE_URL = 'postgres://default:J7BIvaHgmd3l@ep-solitary-breeze-37314604-pooler.us-east-1.postgres.vercel-storage.com:5432/verceldb'
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
c = conn.cursor()
c.execute("SELECT medicine_name, medicine_description, medicine_image, medicine_price FROM vedassist_medicine")
old_medicine_details = []
row = c.fetchall()
for row in row:
old_medicine_details.append(
{
"medicine_name": row[0],
"medicine_description": row[1],
"medicine_image": row[2],
"medicine_price": row[3]
}
)
print("\nOLD MEDICINE DETAILS: \n", old_medicine_details)
#insert medicine_details into postgresql db on vercel
for medicine in medicine_details:
c.execute("INSERT INTO vedassist_medicine (medicine_name, medicine_description, medicine_image, medicine_price, medicine_view_count) VALUES (%s, %s, %s, %s, 0)", (medicine["medicine_name"], medicine["medicine_description"], medicine["medicine_image"], medicine["medicine_price"]))
conn.commit()
c.execute("SELECT medicine_name, medicine_description, medicine_image, medicine_price FROM vedassist_medicine")
new_medicine_details = []
row = c.fetchall()
for row in row:
new_medicine_details.append(
{
"medicine_name": row[0],
"medicine_description": row[1],
"medicine_image": row[2],
"medicine_price": row[3]
}
)
print("\nNEW MEDICINE DETAILS: \n", new_medicine_details)
conn.close()