/
server.py
executable file
·113 lines (91 loc) · 2.73 KB
/
server.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
#!env python2
import os.path
from bottle import route, run, template, view, static_file, request, urlencode
from dcclient import DataCenterClient
from topictrend import TopicTrend
import sample_data
client = DataCenterClient("tcp://10.1.1.211:32011")
print "building topic trend"
topic_trend_client = TopicTrend()
print "building topic trend finished"
@route('/')
def index():
return template('index')
@route('/academic/search')
@view('search')
def search():
q = request.query.q or ''
print 'searching', q, 'in academic'
result = client.searchAuthors(q)
return dict(
query=q,
count=result.total_count,
results=[
dict(
id=a.naid,
name=a.names[0],
email=a.email
) for a in result.authors
],
encoded_query=urlencode({"q": q})
)
@route('/patent/search')
@view('search')
def search():
q = request.query.q or ''
print 'searching', q, 'in patent'
return dict(
query=q,
count=0,
results=[],
encoded_query=urlencode({"q": q})
)
@route('/weibo/search')
@view('search')
def search():
q = request.query.q or ''
print 'searching', q, 'in weibo'
return dict(
query=q,
count=0,
results=[],
encoded_query=urlencode({"q": q})
)
@route('/<data>/topictrends')
@view('topictrends')
def search(data):
q = request.query.q or ''
print 'rendering trends for', q, 'on', data
return dict(
query=q
)
@route('/<data>/terms')
def search(data):
q = request.query.q or ''
start = int(request.query.start) or 0
end = int(request.query.end) or 10000
print 'rendering terms for', q, 'on', data, 'between', start, "and", end
return topic_trend_client.query_terms(q, start_time=start, end_time=end)
@route('/<data>/render')
def topic_trends(data):
q = request.query.q or ''
threshold = request.query.threshold or ''
print 'rendering trends for', q, threshold, 'on', data
return topic_trend_client.query_topic_trends(q, float(threshold))
@route('/<data>/<uid:int>/influence/trends.tsv')
def influence_trends(data, uid):
return open('static/influence.tsv')
@route('/<data>/<uid:int>/influence/topics/<date>')
@view('influence_topics')
def influence_topics(data, uid, date):
# TODO return topics for the given data
return sample_data.influence_topics
@route('/<data>/<uid:int>/influence')
@view('influence')
def influence(data, uid):
return sample_data.influence_index
@route('/static/<path:path>')
def static(path):
curdir = os.path.dirname(os.path.realpath(__file__))
return static_file(path, root=curdir + '/static/')
run(server='auto', host='0.0.0.0', port=8084, reloader=True, debug=True)