-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.py
More file actions
498 lines (441 loc) · 14.1 KB
/
Copy pathrun.py
File metadata and controls
498 lines (441 loc) · 14.1 KB
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
from flask import Flask
from flask import render_template, request, redirect, url_for, session, escape
from flask_cors import CORS
import json
import pymysql
import os
import smtplib
import random
from email.mime.text import MIMEText
PWD = os.path.dirname(os.path.realpath(__file__))
app = Flask(__name__, template_folder="static/templates", static_folder="static")
id = {}
# <------ error hander---------->
@app.errorhandler(500)
def internal_error(error):
return "500 error"
@app.errorhandler(404)
def not_found(error):
return "404 error",404
#<------------------------------>
#<--------cors permission settins----------->
cors = CORS(app, resources={
r"/*": {"origin": "*"},
})
#<------------------------------------------>
def getConnection():
return pymysql.connect(host='54.244.72.128', user='root', password='1234',
db='InterviewNet', charset='utf8')
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' # session key
g_result = {}
idx = 0
API_key = '8674A838-29BC-4AAA-A1F1-5D299D8DE030'
company = ""
major = ""
@app.route('/index')
def index():
return render_template("index.html")
@app.route('/signIn')
def signIn():
return render_template('signin.html')
@app.route('/logIn', methods=['GET','POST'])
def logIn():
if request.method == 'POST':
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
sql = "select userpw from Member where userid = %s"
curs.execute(sql, (jsonObj["userid"]))
result = curs.fetchone()
result = int(result["userpw"])
conn.commit()
print("getUserPW success")
print (result)
print (jsonObj["userpw"])
if result == int(jsonObj["userpw"]):
session['userid'] = jsonObj["userid"]
print ("login Success!!")
return redirect(url_for('index'))
print ("login failed")
return redirect(url_for('index'))
@app.route('/logOut')
def logOut():
# remove the username from the session if its there
session.pop('userid', None)
return redirect(url_for('index'))
@app.route('/idExist', methods=['POST'])
def idExist():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
getId = jsonObj["userid"]
print (jsonObj)
sql = "select userid from Member where userid = %s"
curs.execute(sql,(getId))
id = curs.fetchall()
print (len(id))
result = 1 # true
if len(id) == 0:
result = 0 # false
result = json.dumps(result)
return result
conn.commit()
conn.close()
result = json.dumps(result)
return result
@app.route('/nickExist', methods=['POST'])
def nickExist():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
getNickname = jsonObj["nickname"]
print (jsonObj)
sql = "select nickname from Member where nickname = %s"
curs.execute(sql,(getNickname))
nickname = curs.fetchall()
print (len(nickname))
result = 1 # true
if len(nickname) == 0:
result = 0 # false
result = json.dumps(result)
return result
conn.commit()
conn.close()
result = json.dumps(result)
return result
@app.route('/setSignUp', methods=['POST'])
def setSignUp():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "insert into Member(userid, userpw, city, college, major, town, nickname, username, point, birth, randNum) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
curs.execute(sql,(jsonObj["userid"], jsonObj["userpw"], jsonObj["city"], jsonObj["college"], jsonObj["major"], jsonObj["town"], jsonObj["nickname"], jsonObj["username"], jsonObj["point"], jsonObj["birth"], jsonObj["randNum"]))
conn.commit()
print ("setSignUp success")
conn.close()
return redirect(url_for('index'))
@app.route('/sign_up')
def sign_up():
return render_template("signup.html")
@app.route('/')
def main():
if 'userid' in session:
return 'Logged in as %s' % escape(session['userid'])
return render_template("main.html")
@app.route('/record')
def record():
return render_template('record.html')
@app.route('/sendQuestionOption', methods = ['PUT'])
def getQuestion():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print(jsonObj)
sql = "SELECT * FROM Question WHERE major=%s and company=%s"
curs.execute(sql, (jsonObj["occupation"], jsonObj["company"]))
results = {}
results = curs.fetchall()
jsonObj = json.dumps(results)
conn.commit()
print (jsonObj)
print("getQuestion success.")
conn.close()
return jsonObj
@app.route('/question')
def question():
return render_template("question.html")
@app.route('/matching')
def matching():
return render_template("matching.html")
@app.route('/getMemberInfo', methods=['PUT'])
def getMemberInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "select * from Matching where company = %s and city = %s and town = %s and major = %s"
curs.execute(sql,(jsonObj["company"], jsonObj["city"], jsonObj["town"], jsonObj["major"]))
results = curs.fetchall()
jsonObj = json.dumps(results)
conn.commit()
print (jsonObj)
print ("getMemberInfo success")
conn.close()
return jsonObj
@app.route('/setMember', methods=['POST'])
def setMember():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "insert into Matching(username, city, town, company, major, userInfo) values(%s, %s, %s, %s, %s, %s)"
curs.execute(sql,(jsonObj["username"], jsonObj["city"], jsonObj["town"], jsonObj["company"], jsonObj["major"], jsonObj["userInfo"]))
conn.commit()
print ("setMember success")
conn.close()
return redirect(url_for('matching'))
@app.route('/studyroom')
def studyroom():
return render_template("studyroom.html")
@app.route('/community')
def community():
return render_template("community.html")
@app.route('/write')
def write():
return render_template("write.html")
@app.route('/mypage')
def mypage():
return render_template("mypage.html")
@app.route('/post')
def post():
return render_template("post.html")
@app.route('/getPostInfo', methods=['GET'])
def getPostInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
sql = "select * from Info where id = %s"
global id
curs.execute(sql, (id))
results = curs.fetchone()
jsonObj = json.dumps(results)
conn.commit()
print ("getPostInfo success")
conn.close()
return jsonObj
@app.route('/getInfo', methods=['GET'])
def getInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
sql = "select * from Info order by id desc"
curs.execute(sql)
results = curs.fetchall()
jsonObj = json.dumps(results)
conn.commit()
print (jsonObj)
print ("getInfo success")
conn.close()
return jsonObj
@app.route('/writeInfo', methods=['POST'])
def writeInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "insert into Info(author, title, text, time, hit) values(%s, %s, %s, %s, %s)"
curs.execute(sql, (jsonObj["sid"], jsonObj["stitle"], jsonObj["stext"], jsonObj["stime"], jsonObj["sview"]))
conn.commit()
print ("writeInfo success")
conn.close()
return redirect(url_for('community'))
@app.route('/clickInfo', methods=['PUT'])
def clickInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
jsonObj = request.get_json()
print (jsonObj)
sql = "select hit from Info where id = %s"
curs.execute(sql, (jsonObj["id"]))
sql = "update Info set hit = %s where id = %s"
curs.execute(sql, (jsonObj["sview"], jsonObj["id"]))
conn.commit()
print ("clickInfo success")
global id
id = jsonObj["id"]
conn.close()
return redirect(url_for('post'))
@app.route('/reviseInfo', methods=['PUT'])
def reviseInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
return 1
@app.route('/delInfo', methods=['DELETE'])
def delInfo():
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
return 1
@app.route('/sendEmail', methods=['POST'])
def sendEmail():
smtp = smtplib.SMTP('smtp.live.com', 587)
smtp.ehlo() # say Hello
smtp.starttls() # TLS 사용시 필요
collegeMail = ''
id = ''
smtp.login('kmswin7@gmail.com', '1234')
msg = MIMEText('본문 테스트 메시지')
msg['Subject'] = '테스트'
msg['To'] = id+'@'+collegeMail
smtp.sendmail('kmswin7@gmail.com', id+'@'+collegeMail , msg.as_string())
smtp.quit()
@app.route('/start.interview', methods=['POST'])
def startInterview():
global idx
global g_result
global major
global company
g_result = {}
idx = 0
json_Obj = request.get_json()
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
print(json_Obj)
if (json_Obj['action']['parameters']["company"]["value"] == 'SKT'):
company = 'SK텔레콤'
else:
company = json_Obj['action']['parameters']["company"]["value"]
major = json_Obj['action']['parameters']["major"]["value"]
sql = "select question from Question where company = %s"
curs.execute(sql, (company))
g_result = curs.fetchall()
conn.commit()
print (g_result)
print ("getQuestions success")
conn.close()
idx = random.randrange(0,len(g_result))
curQuestion = g_result[idx]["question"]
json_Obj = {
"version": "2.0",
"resultCode": "OK",
"output": {
'major': major, 'company': company,
'question': curQuestion
},
"directives": [
{
"type": "AudioPlayer.Play",
"audioItem": {
"stream": {
"url": "{{STRING}}",
"offsetInMilliseconds": 600,
"progressReport": {
"progressReportDelayInMilliseconds": 600,
"progressReportIntervalInMilliseconds": 300
},
"token": API_key,
"expectedPreviousToken": "{{STRING}}"
},
"metadata": { }
}
}
]
}
json_Obj = json.dumps(json_Obj, ensure_ascii=False)
return json_Obj
@app.route('/next.interview', methods=['POST'])
def nextInterview():
json_Obj = request.get_json()
print(json_Obj)
global g_result
global idx
global major
global company
idx = idx+1
curQuestion = g_result[idx]["question"]
print (curQuestion)
json_Obj = {
"version": "2.0",
"resultCode": "OK",
"output": {
'major': major, 'company': company,
'question': curQuestion
},
"directives": [
{
"type": "AudioPlayer.Play",
"audioItem": {
"stream": {
"url": "{{STRING}}",
"offsetInMilliseconds": 600,
"progressReport": {
"progressReportDelayInMilliseconds": 600,
"progressReportIntervalInMilliseconds": 300
},
"token": API_key,
"expectedPreviousToken": "{{STRING}}"
},
"metadata": {}
}
}
]
}
json_Obj = json.dumps(json_Obj, ensure_ascii=False)
return json_Obj
@app.route('/search.duedate', methods=['POST'])
def searchDuedate():
json_Obj = request.get_json()
print(json_Obj)
ran = random.randrange(1,60)
json_Obj = {
"version": "2.0",
"resultCode": "OK",
"output": {
'company': company,
'question': ran
},
"directives": [
{
"type": "AudioPlayer.Play",
"audioItem": {
"stream": {
"url": "{{STRING}}",
"offsetInMilliseconds": 600,
"progressReport": {
"progressReportDelayInMilliseconds": 600,
"progressReportIntervalInMilliseconds": 300
},
"token": API_key,
"expectedPreviousToken": "{{STRING}}"
},
"metadata": {}
}
}
]
}
json_Obj = json.dumps(json_Obj, ensure_ascii=False)
return json_Obj
@app.route('/get.Hot', methods=['POST'])
def getHot():
g_result = {}
json_Obj = request.get_json()
print (json_Obj)
conn = getConnection()
curs = conn.cursor(pymysql.cursors.DictCursor)
sql = "select * from Info order by hit desc"
curs.execute(sql)
g_result = curs.fetchall()
conn.commit()
print(g_result)
conn.close()
json_Obj = {
"version": "2.0",
"resultCode": "OK",
"output": {
'popular': g_result[0]["title"],
'question': g_result[0]["text"]
},
"directives": [
{
"type": "AudioPlayer.Play",
"audioItem": {
"stream": {
"url": "{{STRING}}",
"offsetInMilliseconds": 600,
"progressReport": {
"progressReportDelayInMilliseconds": 600,
"progressReportIntervalInMilliseconds": 300
},
"token": API_key,
"expectedPreviousToken": "{{STRING}}"
},
"metadata": {}
}
}
]
}
json_Obj = json.dumps(json_Obj, ensure_ascii=False)
return json_Obj
@app.route('/health', methods=['GET'])
def health():
return "200 OK"
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)