-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
57 lines (48 loc) · 1.51 KB
/
application.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
from flask import Flask,request
from flask import jsonify
from flask import render_template
from flask import send_file
import json
from essearch import ESSearch
# EB looks for an 'application' callable by default.
application = Flask(__name__)
essearch = ESSearch()
@application.route('/')
def index():
return render_template('index.html')
@application.route('/search/')
@application.route('/search/<keyword>')
def search(keyword=None):
if keyword is None:
tweets_of_keyword = {"all": []}
to_return = jsonify(**tweets_of_keyword)
else:
search_result = essearch.search(keyword)
to_return = jsonify(**search_result)
return to_return
@application.route('/geosearch/',methods=['POST'])
def geosearch():
location={"lat": 51.0,"lon": -0.1}
distance=2000
#print location
data = request.form.to_dict()
print data
#location = data['location']
distance = data['distance']
loc = {};
dis = {}
loc['lat'] = data['location[lat]']
loc['lon'] = data['location[lon]']
print location,distance
search_result = essearch.geosearch(loc, distance)
to_return = jsonify(*search_result)
return to_return
@application.route('/images/<filename>')
def get_image(filename=None):
return send_file('static/img/'+filename, mimetype='image/png')
# run the app.
if __name__ == "__main__":
# Setting debug to True enables debug output. This line should be
# removed before deploying a production app.
# application.debug = True
application.run()