forked from Jaram2019/Jaram-Professor-Crawling-Wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
221 lines (173 loc) · 6.3 KB
/
app.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
# -*- coding: utf-8 -*-
"""
Created by IntelliJ IDEA.
Project: Jaram-Professor-Crawler
===========================================
User: ByeongGil Jung
Date: 2019-01-17
Time: 오후 4:08
"""
import config
import json
from crawler.ict import ict_professor as ip
from crawler.soft import soft_professor as sp
from flask import Flask, render_template, request, redirect, url_for, Response
app = Flask(__name__)
# Params
# position = config.POSITION
# Crawling Data
sp_adjunct_data = sp.get_adjunct()
sp_prof_data = sp.get_prof()
sp_honor_data = sp.get_honor()
ip_adjunct_data = ip.get_adjunct()
ip_prof_data = ip.get_prof()
def get_prof_data(switch, name):
prof_data = dict()
if switch == "soft":
# Params
ko_name = "Ko Name"
en_name = "En Name"
status = "Status"
location = "Location"
email = "Email"
photo = "Photo"
# Find the position
prof_list = None
if name in sp_adjunct_data[0]:
prof_list = sp_adjunct_data
elif name in sp_prof_data[0]:
prof_list = sp_prof_data
elif name in sp_honor_data[0]:
prof_list = sp_honor_data
# Count the number
prof_count = 0
for i in range(len(prof_list[0])):
if name == prof_list[0][i]:
prof_count = i
# Put data to variable
for i in range(len(prof_list)):
if i == 0:
ko_name = prof_list[i][prof_count]
elif i == 1:
en_name = prof_list[i][prof_count]
elif i == 2:
status = prof_list[i][prof_count]
elif i == 3:
location = prof_list[i][prof_count]
elif i == 4:
email = prof_list[i][prof_count]
elif i == 5:
photo = prof_list[i][prof_count]
prof_data = {"ko_name": ko_name,
"en_name": en_name,
"status": status,
"location": location,
"email": email,
"photo": photo}
elif switch == "ict":
# Params
ko_name = "Ko Name"
en_name = "En Name"
status = "Status"
location = "Location"
phone = "Phone"
email = "Email"
photo = "photo"
# Find the position
prof_list = None
if name in ip_adjunct_data[0]:
prof_list = ip_adjunct_data
elif name in ip_prof_data[0]:
prof_list = ip_prof_data
# Count the number
prof_count = 0
for i in range(len(prof_list[0])):
if name == prof_list[0][i]:
prof_count = i
# Put data to variable
for i in range(len(prof_list)):
if i == 0:
ko_name = prof_list[i][prof_count]
elif i == 1:
en_name = prof_list[i][prof_count]
elif i == 2:
status = prof_list[i][prof_count]
elif i == 3:
location = prof_list[i][prof_count]
elif i == 4:
phone = prof_list[i][prof_count]
elif i == 5:
email = prof_list[i][prof_count]
elif i == 6:
photo = prof_list[i][prof_count]
prof_data = {"ko_name": ko_name,
"en_name": en_name,
"status": status,
"location": location,
"phone": phone,
"email": email,
"photo": photo}
return prof_data
@app.route("/")
def root():
soft_prof_list = sp_prof_data[0]
soft_honor_list = sp_honor_data[0]
soft_adjunct_list = sp_adjunct_data[0]
ict_adjunct_list = ip_adjunct_data[0]
ict_prof_list = ip_prof_data[0]
return render_template("index.html",
soft_prof_list=soft_prof_list,
soft_honor_list=soft_honor_list,
soft_adjunct_list=soft_adjunct_list,
ict_adjunct_list=ict_adjunct_list,
ict_prof_list=ict_prof_list)
@app.route("/software_professor/<name>")
def render_software_professor_controller(name):
soft_prof_list = sp_prof_data[0]
soft_honor_list = sp_honor_data[0]
soft_adjunct_list = sp_adjunct_data[0]
ict_adjunct_list = ip_adjunct_data[0]
ict_prof_list = ip_prof_data[0]
prof_data = get_prof_data("soft", name)
return render_template("professor_info.html",
soft_prof_list=soft_prof_list,
soft_honor_list=soft_honor_list,
soft_adjunct_list=soft_adjunct_list,
ict_adjunct_list=ict_adjunct_list,
ict_prof_list=ict_prof_list,
prof_data=prof_data)
@app.route("/ict_professor/<name>")
def render_ict_professor_controller(name):
soft_prof_list = sp_prof_data[0]
soft_honor_list = sp_honor_data[0]
soft_adjunct_list = sp_adjunct_data[0]
ict_adjunct_list = ip_adjunct_data[0]
ict_prof_list = ip_prof_data[0]
prof_data = get_prof_data("ict", name)
return render_template("professor_info.html",
soft_prof_list=soft_prof_list,
soft_honor_list=soft_honor_list,
soft_adjunct_list=soft_adjunct_list,
ict_adjunct_list=ict_adjunct_list,
ict_prof_list=ict_prof_list,
prof_data=prof_data)
@app.route("/wiki/get", methods=["GET"])
def get_wiki_context():
# When init rendering the page (at first)
name = request.args.get("prof_name")
# 여기에 db 함수 넣을 것
# print(name)
context = "교수님 좋아요 ~~~~" # db 결과 받아 올 것
res = json.dumps({"context": context})
return Response(res, status=200, mimetype="application/json")
@app.route("/wiki/write", methods=["POST"])
def write_wiki_context():
name = request.form["prof_name"]
context = request.form["context"]
# context = context # db 결과 받아 올 것
# 여기에 db 함수 넣을 것
# print(context)
res = json.dumps({"context": context})
return Response(res, status=200, mimetype="application/json")
if __name__ == "__main__":
app.run(debug=True, port=9999)