Last active
August 23, 2019 21:02
-
-
Save haithamsha/ebb9c9304d1aa5cd40e876eddfb67f88 to your computer and use it in GitHub Desktop.
Get restaurants info with name and meal type using google api's and foursquare api's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
import json | |
import sys | |
import codecs | |
sys.stdout = codecs.getwriter('utf8')(sys.stdout) | |
sys.stderr = codecs.getwriter('utf8')(sys.stderr) | |
# gapi_key="your key" | |
def findAResturant(mealType, location): | |
clientId = "your key" | |
clientSecret = "your key" | |
url = ('https://api.foursquare.com/v2/venues/search?client_id=%s&client_secret=%s&ll=%s&v=20190812&query=%s' | |
%(clientId, clientSecret, location, mealType)) | |
h = httplib2.Http() | |
result = json.loads(h.request(url, 'GET')[1]) | |
if result['response']['venues']: | |
resturantData = result['response']['venues'][0] | |
name = resturantData['name'] | |
address = resturantData['location']['address'] | |
#get resturant image | |
vImage = getVenuePhoto("4bc9a82e3740b71317045f65") | |
resturantInfo = {'name': name, 'address': address, 'imageUrl': vImage} | |
#print resturant information | |
print "Resturant Name: %s" % resturantInfo['name'] | |
print "Resturant Address: %s" % resturantInfo['address'] | |
print "Image: %s \n" % resturantInfo['imageUrl'] | |
else: | |
print "Resturant Not Found!" | |
def getVenuePhoto(venuId): | |
clientId = "your key" | |
clientSecret = "your key" | |
url = ('https://api.foursquare.com/v2/venues/%s/photos?client_id=%s&client_secret=%s&v=20190812' | |
%(venuId, clientId, clientSecret)) | |
h = httplib2.Http() | |
result = json.loads(h.request(url, 'GET')[1]) | |
if result['response']['photos']: | |
prefix = result['response']['photos']['items'][0]['prefix'] | |
# width = result['response']['photos']['items'][0]['width'] | |
# height = result['response']['photos']['items'][0]['height'] | |
suffix = result['response']['photos']['items'][0]['suffix'] | |
return prefix + "300x300" + suffix | |
else: | |
return "https://cdn.pixabay.com/photo/2014/06/11/17/00/cook-366875_960_720.jpg" | |
findAResturant("sushi", "29.958348,31.259629") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment