-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (49 loc) · 1.67 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
from flask import Flask
from flask import render_template
from flask import request
import package.web as web
from threading import Thread
# CommentsThread helps to get result from threads
class CommentsThread(Thread):
def __init__(self, url):
Thread.__init__(self)
self.url = url
def run(self):
self.result = web.GetComment(self.url)
def get_result(self):
return self.result
app = Flask(__name__)
# a beautiful searching page
@app.route('/', methods = ['POST', 'GET'])
def index():
if request.method == 'GET':
return render_template('indexsearch.html')
# a beautiful presenting page
@app.route('/wordcloud', methods = ['POST', 'GET'])
def result():
Course_Name = str(request.args.get('name'))
# get links and comments
links = web.SearchCourse(Course_Name)
comments_thd = list(map(CommentsThread,links))
for threads in comments_thd:
threads.start()
for threads in comments_thd:
threads.join()
all_course_comments = []
for i in range(len(links)):
all_course_comments.append(comments_thd[i].get_result())
# generating wordclouds
k = 0
for i in range(len(all_course_comments)):
if len(all_course_comments[i]) != 0:
web.TheWordCloud(all_course_comments[i],i)
k = k + 1
print(str(k) + " picture drown...")
print("all pictures finished, please check static//wordcloud")
# present these pictures
Names= []
for i in range(6):
Names.append('./wordcloud/' + str(i) + '.png')
return render_template('wordcloud.html', PictureNames=Names)
if __name__ == '__main__':
app.run()