-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathupdate_project_eng.py
158 lines (134 loc) · 7.88 KB
/
update_project_eng.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from UnoCPI import sqlfiles,settings
import psycopg2
import os
sql = sqlfiles
global connection
global cursor
try:
connection = psycopg2.connect(user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['PASSWORD'],
host=settings.DATABASES['default']['HOST'],
port=settings.DATABASES['default']['PORT'],
database=settings.DATABASES['default']['NAME'],
sslmode="require")
if connection:
print("Postgres SQL Database successful connection")
cursor = connection.cursor()
print("Executing Community Partner status inactive")
#UPDATE Community partner to show status 'Inactive' from newly added Partner Status Table
activityTypeDict_SL = []
activityTypeDict_SL.append({'oldValue':'Meeting / Gathering','newValue':'Other'})
activityTypeDict_SL.append({'oldValue':'Course','newValue':'Course'})
activityTypeDict_SL.append({'oldValue':'Unpaid Services','newValue':'Other'})
activityTypeDict_SL.append({'oldValue':'General Activity','newValue':'Course'})
activityTypeDict_SL.append({'oldValue':'Event / Exhibit / Performance','newValue':'Course'})
for x in activityTypeDict_SL:
print(x['oldValue'],x['newValue'])
query = "update projects_project set activity_type_id = \
(select a.id from projects_activitytype as a where a.name = '%s') \
where engagement_type_id = \
(select e.id from projects_engagementtype as e where e.name = 'Service Learning') \
and activity_type_id = \
(select c.id from projects_activitytype as c where c.name = '%s')"
print('query--',query)
cursor.execute(query, (x['newValue'],x['oldValue'], ))
connection.commit()
activityTypeDict_AH = []
activityTypeDict_AH.append({"oldValue":'Unpaid Services',"newValue":'Other'})
activityTypeDict_AH.append({"oldValue":'Course',"newValue":'Other'})
activityTypeDict_AH.append({"oldValue":'Event / Exhibit / Performance',"newValue":'Other'})
activityTypeDict_AH.append({"oldValue":'Capstone',"newValue":'Other'})
activityTypeDict_AH.append({"oldValue":'Workshop',"newValue":'Other'})
activityTypeDict_AH.append({"oldValue":'Internships',"newValue":'Other'})
for x in activityTypeDict_AH:
print(x['oldValue'],x['newValue'])
query_AH = "update projects_project set activity_type_id = \
(select a.id from projects_activitytype as a where a.name = '%s') \
where engagement_type_id = \
(select e.id from projects_engagementtype as e where e.name = 'Access to Higher Education') \
and activity_type_id = \
(select c.id from projects_activitytype as c where c.name = '%s')"
print('query--',query_AH)
cursor.execute(query_AH, (x['newValue'],x['oldValue'], ))
connection.commit()
activityTypeDict_CM = []
activityTypeDict_CM.append({"oldValue":'Unpaid Services',"newValue":'Other'})
activityTypeDict_CM.append({"oldValue":'Course',"newValue":'Other'})
activityTypeDict_CM.append({"oldValue":'General Activity',"newValue":'Other'})
activityTypeDict_CM.append({"oldValue":'Contract Services',"newValue":'Other'})
activityTypeDict_CM.append({"oldValue":'Training / Workshop / Presentation',"newValue":'Other'})
activityTypeDict_CM.append({"oldValue":'Event / Exhibit / Performance',"newValue":'Other'})
for x in activityTypeDict_CM:
print(x['oldValue'],x['newValue'])
query_CM = "update projects_project set activity_type_id = \
(select a.id from projects_activitytype as a where a.name = '%s') \
where engagement_type_id = \
(select e.id from projects_engagementtype as e where e.name = 'Community-Based Learning') \
and activity_type_id = \
(select c.id from projects_activitytype as c where c.name = '%s')"
print('query--',query_CM)
cursor.execute(query_CM, (x['newValue'],x['oldValue'], ))
connection.commit()
activityTypeDict_ER = []
activityTypeDict_ER.append({"oldValue":'Unpaid Services',"newValue":'Other'})
activityTypeDict_ER.append({"oldValue":'Course',"newValue":'Other'})
activityTypeDict_ER.append({"oldValue":'Contract Services',"newValue":'Other'})
activityTypeDict_ER.append({"oldValue":'Mentoring',"newValue":'Other'})
activityTypeDict_ER.append({"oldValue":'Workshop',"newValue":'Other'})
activityTypeDict_ER.append({"oldValue":'Internships',"newValue":'Other'})
for x in activityTypeDict_ER:
print(x['oldValue'],x['newValue'])
query_ER = "update projects_project set activity_type_id = \
(select a.id from projects_activitytype as a where a.name = '%s') \
where engagement_type_id = \
(select e.id from projects_engagementtype as e where e.name = 'Engaged Research') \
and activity_type_id = \
(select c.id from projects_activitytype as c where c.name = '%s')"
print('query--',query_ER)
cursor.execute(query_ER, (x['newValue'],x['oldValue'], ))
connection.commit()
activityTypeDict_KR = []
activityTypeDict_KR.append({"oldValue":'General Activity',"newValue":'Other'})
activityTypeDict_KR.append({"oldValue":'Course',"newValue":'Other'})
activityTypeDict_KR.append({"oldValue":'Meeting/Gathering',"newValue":'Community-oriented lecture/event'})
activityTypeDict_KR.append({"oldValue":'Unpaid Services',"newValue":'Other'})
activityTypeDict_KR.append({"oldValue":'Event / Exhibit / Performance',"newValue":'Community-oriented lecture/event'})
activityTypeDict_KR.append({"oldValue":'Contract Services',"newValue":'Specialized Service Contract'})
activityTypeDict_KR.append({"oldValue":'Training / Workshop / Presentation',"newValue":'Workshop'})
activityTypeDict_KR.append({"oldValue":'Service Activity',"newValue":'Workshop'})
activityTypeDict_KR.append({"oldValue":'Student Research',"newValue":'Workshop'})
for x in activityTypeDict_KR:
print(x['oldValue'],x['newValue'])
query_KR = "update projects_project set activity_type_id = \
(select a.id from projects_activitytype as a where a.name = '%s') \
where engagement_type_id = \
(select e.id from projects_engagementtype as e where e.name = 'Knowledge and Resource Sharing') \
and activity_type_id = \
(select c.id from projects_activitytype as c where c.name = '%s')"
print('query--',query_KR)
cursor.execute(query_KR, (x['newValue'],x['oldValue'], ))
connection.commit()
activityTypeDict_VL = []
activityTypeDict_VL.append({"oldValue":'Unpaid Services',"newValue":'Service Activity'})
activityTypeDict_VL.append({"oldValue":'Course',"newValue":'Other'})
activityTypeDict_VL.append({"oldValue":'General Activity',"newValue":'Service Activity'})
activityTypeDict_VL.append({"oldValue":'Contract Services',"newValue":'Other'})
activityTypeDict_VL.append({"oldValue":'Workshop',"newValue":'Other'})
activityTypeDict_VL.append({"oldValue":'Training / Workshop / Presentation',"newValue":'Other'})
activityTypeDict_VL.append({"oldValue":'Meeting / Gathering',"newValue":'Other'})
for x in activityTypeDict_VL:
print(x['oldValue'],x['newValue'])
query_VL = "update projects_project set activity_type_id = \
(select a.id from projects_activitytype as a where a.name = '%s') \
where engagement_type_id = \
(select e.id from projects_engagementtype as e where e.name = 'Volunteering') \
and activity_type_id = \
(select c.id from projects_activitytype as c where c.name = '%s')"
print('query--',query_VL)
cursor.execute(query_VL, (x['newValue'],x['oldValue'], ))
connection.commit()
except (psycopg2.Error) as error:
print("Error while connecting to Postgres SQL", error)
cursor.close()
connection.close()
print("Postgres SQL connection is closed")