-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapplication.py
More file actions
executable file
·76 lines (63 loc) · 2.62 KB
/
application.py
File metadata and controls
executable file
·76 lines (63 loc) · 2.62 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
from flask import Flask,redirect
from flask import render_template
from pyes import *
from flask import request
import json
import requests
from wsgiref.simple_server import make_server
import flask_googlemaps
from flask import jsonify
# Address of the elasticsearch host
elasticsearchURL = 'https://search-twittmap-77ta2y45lfunfg4hhdxaezl524.us-west-2.es.amazonaws.com'
application = Flask(__name__)
application.config['GOOGLEMAPS_KEY']="AIzaSyC403JgsSdPSph8zoqbPs9DMzkLosIRD6o"
flask_googlemaps.GoogleMaps(application)
res_count = requests.get(elasticsearchURL + '/test-index/test-type/_count')
count_json = json.loads(res_count.text.replace("\\", r"\\"))
@application.route('/location')
def getlocation():
a = request.args.get('lat',10,type=float)
b = request.args.get('lng',10,type=float)
results = getMessageByLocation((a,b))
return results
def getMessageByLocation(location):
conn = ES(['https://search-twittmap-77ta2y45lfunfg4hhdxaezl524.us-west-2.es.amazonaws.com'])
latitute,longitute=location
print("LAT!!!!!",latitute,"Long",longitute)
if dd_select=='':
q=MatchAllQuery()
else:
q=TermQuery("message",dd_select)
f=GeoDistanceFilter("location",{"lat":latitute,"lon":longitute},'100mi')
s=FilteredQuery(q,f)
results=conn.search(query=s)
ret = {'res':[]}
try:
for result in results:
ret['res'].append([result['location']['lat'], result['location']['lon']])
return jsonify(**ret)
except:
print ("No twitter Nearby")
@application.route('/',methods=['POST'])
def backend_query():
global dd_select
dd_select = request.form['keyword_drop_down']
global selected
selected = dd_select
conn = ES(['https://search-twittmap-77ta2y45lfunfg4hhdxaezl524.us-west-2.es.amazonaws.com'])
cLat = request.args.get('lat',10,type=float)
cLon = request.args.get('lng',10,type=float)
q=TermQuery("message",dd_select)
results=conn.search(query=q)
coord_list = []
for i in results:
if (i["location"]["lat"]) is not None:
coordinates = str(i["location"]["lat"])+","+str(i["location"]["lon"])
coord_list.append(coordinates)
return render_template('MapUI.html', count = count_json['count'], coord_list = coord_list, selected = selected, keyword = dd_select)
@application.route('/', methods=['GET','POST'])
def home():
return render_template('MapUI.html', count = count_json['count'], coord_list = [], keyword = "select")
if __name__ == '__main__':
application.run(host='127.0.0.1')
make_server("LowCost-env.zpivveuucj.us-west-2.elasticbeanstalk.com", application).serve_forever()