forked from codeforamerica/sheltraustin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryHandler.py
42 lines (35 loc) · 1.17 KB
/
QueryHandler.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
import simplejson, urllib
from MapHandler import MapHandler
from SMSHandler import SMSHandler
from EmailHandler import EmailHandler
import os
class QueryHandler(object):
PLACES_API_KEY = (os.environ.get("GOOGLE_KEY"))
@classmethod
def get_map(self, json):
"""Return the Google Maps API JSON Object."""
mp = MapHandler()
map_json = mp.getAllServiceProviders(json)
return map_json
@classmethod
def get_addresses(self, json):
"""Return the potential autocomplete addresses."""
address = json['address']
url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%s&types=geocode&components=country:us&language=en&sensor=true&key=%s' % (address, self.PLACES_API_KEY)
google_results = simplejson.load(urllib.urlopen(url))
output = {
'addresses': []
}
for location in google_results['predictions']:
description = location['description']
output['addresses'].append(description)
# endfor location
return output
@classmethod
def get_sms(self, recipient, msgbody):
sh = SMSHandler()
return sh.sendSMS(recipient,msgbody)
@classmethod
def get_email(self, recipient, msgbody):
eh = EmailHandler()
return eh.sendEmail(recipient, msgbody)