-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate_announcements_dismissal.py
59 lines (44 loc) · 1.43 KB
/
migrate_announcements_dismissal.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
#!/usr/bin/python
import os
import psycopg2
import sys
file = open("/home/" + os.getlogin() + "/.pgpass", "r")
pgpasses = []
for line in file:
pgpasses.append(line.rstrip("\n").split(":"))
file.close()
for pgpass in pgpasses:
#print str(pgpass)
if pgpass[0] == "54.236.235.110" and pgpass[3] == "geonode":
src_pgpass = pgpass
if pgpass[0] == "54.197.226.56" and pgpass[3] == "geonode":
dst_pgpass = pgpass
src = psycopg2.connect(host=src_pgpass[0], database="geonode2", user=src_pgpass[3], password=src_pgpass[4])
dst = psycopg2.connect(host=dst_pgpass[0], database="geonode", user=dst_pgpass[3], password=dst_pgpass[4])
src_cur = src.cursor()
dst_cur = dst.cursor()
src_cur.execute("select id, user_id, announcement_id, dismissed_at from announcements_dismissal")
for src_row in src_cur:
assignments = []
#id
assignments.append(src_row[0])
#user_id
assignments.append(src_row[1])
#announcement_id
assignments.append(src_row[2])
#dismissed_at
assignments.append(src_row[3])
try:
dst_cur.execute("insert into announcements_dismissal(id, user_id, announcement_id, dismissed_at) values (%s, %s, %s, %s)", assignments)
dst.commit()
except Exception as error:
print
print type(error)
print str(error) + "select id, user_id, announcement_id, dismissed_at from announcements_dismissal"
print str(src_row)
dst.rollback()
dst.commit()
src_cur.close()
dst_cur.close()
src.close()
dst.close()