-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
354 lines (326 loc) · 14.2 KB
/
main.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import mysql.connector
import setparty
import test
import setorig
import setprovince
import setDB
import setcomittee
import setproposal
import setevaluation
from setdatabase import database_setting
set_DB_using_openAPI = '1'
search_assemblyman = '2'
search_party = '3'
search_committee = '4'
search_proposal = '5'
search_province = '6'
evaluate = '7'
def print_menu():
print("*--------------------------------------------------------------*")
print("| # Database Team 'Project JJ' # |")
print("*--------------------------------------------------------------*")
print("| 1. 오픈 API 를 이용한 DB 세팅 |")
print("| 2. 국회의원 이름 검색 |")
print("| 3. 정당 이름 검색 |")
print("| 4. 위원회 검색 |")
print("| 5. 발의안 검색 |")
print("| 6. 지역 검색 |")
print("| 7. 국회의원 평가 |")
print("| else. 종료 |")
print("*--------------------------------------------------------------*")
def createView(cnx, cursor):
query = "SELECT * " \
"FROM assemblyman " \
# "where assemblyman.empNm = '나경원' "
cursor.execute(query)
result_assemblyman = cursor.fetchall()
for tup in result_assemblyman:
view_assemblymanCd = tup[0]
view_empNm = tup[1]
view_partyNm = tup[2]
view_reeleGbnNm = tup[3]
query = "SELECT runningarea.RunningAreaNm " \
"FROM runningarea " \
"WHERE runningarea.runningAreaCd = '" + tup[4] + "'"
cursor.execute(query)
result_origNm = cursor.fetchall()
view_origNm = result_origNm[0][0]
view_hobbyNm = ""
if tup[5]:
view_hobbyNm = tup[5]
query = "SELECT comitteeCd " \
"FROM assemblyman natural join assemblyman_has_comittee " \
"WHERE assemblyman.empNm = '" + view_empNm + "'"
cursor.execute(query)
result_comitteeCd = cursor.fetchall()
view_comitteeNm = ""
if not len(result_comitteeCd) == 0:
for comitteeCd in result_comitteeCd:
query = "SELECT comitteeNm " \
"FROM comittee " \
"WHERE comittee.comitteeCd = '" + comitteeCd[0] + "'"
cursor.execute(query)
result_comitteeNm = cursor.fetchall()[0]
# print("*위원회 : ", end="")
temp_comitteeNm = ""
for comitteeNm in result_comitteeNm:
view_comitteeNm += comitteeNm + ", "
# print(view_empNm, view_partyNm, view_reeleGbnNm, view_origNm, view_hobbyNm, view_comitteeNm)
view_query = "CREATE OR REPLACE VIEW assemblyman_view AS " \
"SELECT distinct assemblyman.assemblymanCd, assemblyman.empNm, assemblyman.partyNm, assemblyman.reeleGbnNm, runningarea.RunningAreaNm AS origNm, assemblyman.hobbyNm " \
"FROM assemblyman, runningarea " \
"WHERE assemblyman.origCd = runningarea.runningAreaCd;"
cursor.execute(view_query)
cnx.commit()
# 1. 오픈 API 를 이용한 DB 세팅
def DB_setting(cnx, cursor):
print("*--------------------------------------------------------------*")
setparty.partyset(cnx, cursor)
print("■■", end="")
setprovince.provinceset(cnx, cursor)
print("■■", end="")
setorig.origset(cnx, cursor)
print("■■", end="")
setDB.assemblymanset(cnx, cursor)
setcomittee.comitteeset(cnx, cursor)
print("■■", end="")
setcomittee.assemblyman_has_comitteeset(cnx, cursor)
print("■■", end="")
setproposal.proposalset(cnx, cursor)
print("■■", end="")
setproposal.assemblyman_has_proposal(cnx, cursor)
print("■■", end="")
createView(cnx, cursor)
print("■■", end="")
setevaluation.initrep(cnx, cursor)
print("■■■", end="")
setevaluation.setreptrigger(cnx, cursor)
print("■■■")
# 2. 국회의원 이름 검색
def assemblyman_searching():
search_man_name = input("\n검색할 국회의원 이름 >> ")
query = "SELECT * " \
"FROM assemblyman_view " \
"WHERE assemblyman_view.empNm = '" + search_man_name + "'"
cursor.execute(query)
result_assemblyman = cursor.fetchall()
if len(result_assemblyman) == 0:
print("*ERROR : %s 은 존재하지 않는 국회의원입니다." % search_man_name)
return
elif len(result_assemblyman) > 1:
print("*동명이인이 있습니다.")
for tup in result_assemblyman:
print("*--------------------------------------------------------------*")
print("*국회의원 : " + tup[1])
print("*소속정당 : " + tup[2])
print("*당선횟수 : " + tup[3])
print("*선거구 : " + tup[4])
print("*취미 : " + tup[5])
print("*위원회 : ", end="")
query = "SELECT comitteeCd " \
"FROM assemblyman natural join assemblyman_has_comittee " \
"WHERE assemblyman.assemblymanCd = '" + tup[0] + "'"
cursor.execute(query)
result_comitteeCd = cursor.fetchall()
view_comitteeNm = ""
if not len(result_comitteeCd) == 0:
for comitteeCd in result_comitteeCd:
query = "SELECT comitteeNm " \
"FROM comittee " \
"WHERE comittee.comitteeCd = '" + comitteeCd[0] + "'"
cursor.execute(query)
result_comitteeNm = cursor.fetchall()[0]
temp_comitteeNm = ""
for comitteeNm in result_comitteeNm:
view_comitteeNm += comitteeNm + ", "
if len(result_comitteeCd) == 0:
print("X", end="")
else:
print(view_comitteeNm, end="")
print()
query = "SELECT reputation " \
"FROM assemblyman " \
"WHERE assemblyman.assemblymanCd = '" + tup[0] + "'"
cursor.execute(query)
result_reputation = cursor.fetchall()
print("*평판점수 : " + str(result_reputation.pop()[0]))
query = "SELECT content " \
"FROM evaluation " \
"WHERE evaluation.assemblymanCd = '" + tup[0] + "'"
cursor.execute(query)
result_content = cursor.fetchall()
if len(result_content) != 0:
print("*코멘트 : " + result_content[0][0])
print()
# 3. 정당 이름 검색
def party_searching():
query = "SELECT Party.partyNm FROM Party"
cursor.execute(query)
temp_party = cursor.fetchall()
searchable_party = []
print("*------------------------검색 가능한 당명----------------------*")
for tup in temp_party:
print("%26s" % tup)
searchable_party.append(tup[0])
print("*--------------------------------------------------------------*")
search_party_name = input("\n검색할 당명 >> ")
if search_party_name not in searchable_party:
print("*ERROR : %s 은 없는 정당명입니다." % search_party_name)
return
query = "SELECT * " \
"FROM Party " \
"WHERE Party.partyNm = '" + search_party_name + "'"
cursor.execute(query)
result = cursor.fetchall()
for tup in result:
print(tup[1] + "의 국회 의석 수 : " + tup[2] + ", 당대표 : " + tup[3] + ", 창당일 : " + tup[4])
query = "SELECT empNm " \
"FROM Assemblyman natural join Party " \
"WHERE Party.partyNm = '" + search_party_name + "'"
cursor.execute(query)
result = cursor.fetchall()
print("--------------" + search_party_name + "에 소속한 국회의원-----------")
for i, tup in enumerate(result):
print("%3d. %s" % (i+1, tup[0]))
# 4. 위원회 검색
def committee_searching():
query = "SELECT comittee.comitteeNm " \
"FROM comittee"
cursor.execute(query)
temp_comittee = cursor.fetchall()
searchable_comittee = []
print("*--------------------검색 가능한 위원회 명---------------------*")
for tup in temp_comittee:
print("%26s" % tup[0])
searchable_comittee.append(tup[0])
print("*--------------------------------------------------------------*")
search_comittee_name = input("\n검색할 위원회 >> ")
if search_comittee_name not in searchable_comittee:
print("*ERROR : %s 은 없는 위원회입니다." % search_comittee_name)
return
query = "SELECT comitteeCd, chairmanCd " \
"FROM comittee where comittee.comitteeNm = '" + search_comittee_name + "'"
cursor.execute(query)
result_comittee = cursor.fetchall()[0]
query = "SELECT assemblyman.empNm " \
"FROM assemblyman " \
"WHERE assemblyman.assemblymanCd = '" + result_comittee[1] + "'"
cursor.execute(query)
result_chairmanNm = cursor.fetchall()[0][0]
query = "SELECT empNm, partyNm " \
"FROM assemblyman " \
"WHERE assemblymanCd in " \
"(SELECT assemblymanCd " \
"FROM assemblyman_has_comittee " \
"WHERE comitteeCd = '" + result_comittee[0] + "')"
cursor.execute(query)
result_memberNm = cursor.fetchall()
print("\n*--------------------------------------------------------------*")
print("%16s 인원수 : %s명, 의원회장 : %s" % (search_comittee_name, str(len(result_memberNm)), result_chairmanNm))
print("*----------------" + search_comittee_name + "에 소속한 국회의원------------------*")
for memberNm in result_memberNm:
print("%15s%15s" % (memberNm[0], memberNm[1]))
# 5. 발의안 검색
def proposal_searching():
query = "SELECT proposalNm " \
"FROM proposal"
cursor.execute(query)
temp_comittee = cursor.fetchall()
searchable_proposal = []
print("*--------------------검색 가능한 발의안 명---------------------*")
for i, tup in enumerate(temp_comittee):
print("%2d. %s" % (i+1, tup[0]))
searchable_proposal.append(tup[0])
print("*--------------------------------------------------------------*")
search_proposal_name = input("\n검색할 발의안 키워드 >> ")
query = "SELECT proposalCd, proposalNm, proposerCd " \
"FROM proposal where proposalNm like '%" + search_proposal_name + "%'"
cursor.execute(query)
search_result = cursor.fetchall()
if len(search_result) == 0:
print("*ERROR : %s 은 없는 위원회입니다." % search_proposal_name)
return
while True:
print("*-------------------- 검색 결과 %d개 ---------------------*" % len(search_result))
for i, tup in enumerate(search_result):
print("%2d. %s" % (i+1, tup[1]))
print("*--------------------------------------------------------------*")
search_proposal_num = input("\n검색할 발의안 번호(숫자만 입력) >> ")
if int(search_proposal_num) <= len(search_result):
break
else:
print("*ERROR : %s 는 잘못된 번호입니다." % search_proposal_num)
search_one = search_result[int(search_proposal_num)-1]
query = "SELECT assemblyman.empNm " \
"FROM assemblyman " \
"WHERE assemblyman.assemblymanCd = '" + search_one[2] + "'"
cursor.execute(query)
result_chairmanNm = cursor.fetchall()
query = "SELECT empNm, partyNm " \
"FROM assemblyman " \
"WHERE assemblymanCd in " \
"(SELECT assemblymanCd " \
"FROM assemblyman_has_proposal " \
"WHERE proposalCd = '" + search_one[0] + "')"
cursor.execute(query)
result_memberNm = cursor.fetchall()
print("\n*--------------------------------------------------------------*")
print("%16s 발의자수 : %s명, 대표 발의자 : %s" % (search_one[1], str(len(result_memberNm)), result_chairmanNm.pop()[0]))
print("*-------" + search_one[1] + " 발의 국회의원 목록----------*")
for memberNm in result_memberNm:
print("%15s%15s" % (memberNm[0], memberNm[1]))
# 6. 지역 검색
def province_searching():
query = "SELECT * FROM province"
cursor.execute(query)
temp_province = cursor.fetchall()
searchable_province = []
print("*----------------------검색 가능한 지역--------------------*")
for tup in temp_province:
print("%26s" % tup[1])
searchable_province.append(tup[1])
print("*----------------------------------------------------------*")
search_province_name = input("\n검색할 지역 >> ")
if search_province_name not in searchable_province:
print("*ERROR : %s 은 없는 지역입니다." % search_province_name)
return
query = "select empNm, partyNm " \
"from assemblyman " \
"where origCd in " \
"(SELECT runningAreaCd " \
"FROM runningarea natural join province " \
"WHERE provinceNm = '" + search_province_name + "')"
cursor.execute(query)
result_manNm = cursor.fetchall()
print("*-----------%7s에 소속한 국회의원 %2d명----------*" % (search_province_name, len(result_manNm)))
for manNm in result_manNm:
print("%12s %16s" % (manNm[0], manNm[1]))
print()
# 7. 국회의원 평가
def evaluate_assemblyman():
setevaluation.evaluation(cnx, cursor)
pass
if __name__ == '__main__':
cnx, cursor = database_setting()
while True:
print_menu()
menuNum = input(">> ")
if menuNum == set_DB_using_openAPI:
DB_setting(cnx, cursor)
elif menuNum == search_assemblyman:
assemblyman_searching()
elif menuNum == search_party:
party_searching()
elif menuNum == search_committee:
committee_searching()
elif menuNum == search_proposal:
proposal_searching()
elif menuNum == search_province:
province_searching()
elif menuNum == evaluate:
evaluate_assemblyman()
else:
print("*프로그램 종료")
cursor.close()
cnx.close()
break