-
Notifications
You must be signed in to change notification settings - Fork 0
/
restaurant.py
31 lines (25 loc) · 1.29 KB
/
restaurant.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
import json
import httplib2
import sys
import codecs
foursquare_client_id = 'A5SLLJZFCW5YJH1OFDSJ2ANDKBGFQIJZGENOEZTMITSY5LJS'
foursquare_client_secret = 'AAT153KQCIEG3CHYX5JLVMCZ5UBQH4FCVA0LXSVKAYJFBNFI'
google_api_key = 'AIzaSyAox4Mjj81wNdY-RQuYB496vJ8j0ilu80o'
def getGeocodeLocation(inputString):
#Replace Spaces with '+' in URL
locationString = inputString.replace(" ", "+")
url = ('https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s'%(locationString,google_api_key))
# url = ('https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s'%(locationString, google_api_key))
h = httplib2.Http()
result = json.loads(h.request(url,'GET')[1])
#print response
latitude = result['results'][0]['geometry']['location']['lat']
longitude = result['results'][0]['geometry']['location']['lng']
return (latitude,longitude)
def findARestaurant(mealType, location):
latitude, longitude = getGeocodeLocation(location)
url = ('https://api.foursquare.com/v2/venues/search?client_id=%s&client_secret=%s&v=20130815&ll=%s,%s&query=%s'%(foursquare_client_id, foursquare_client_secret,latitude,longitude,mealType))
h = httplib2.Http()
result = json.loads(h.request(url,'GET')[1])
return result
# bang = getGeocodeLocation("Banglore karnataka")