コード例 #1
0
def search(request):
	p = Pyzomato('')
	list = []
	try:
		searchCategory = request.GET.get('searchCategory','')
		searchKeyWord = request.GET.get('searchKeyWord','')
		response=''
		if searchCategory == 'cuisines':
			cuisine_id = ''
			cusineResponse = p.getCuisines(city_id = '4')
			for num, cuisine in enumerate(cusineResponse['cuisines']):
				if cuisine['cuisine']['cuisine_name'] == searchKeyWord:
					cuisine_id = cuisine['cuisine']['cuisine_id']
			response = p.search(entity_type="city", entity_id='4',cuisines=cuisine_id)
		if searchCategory == 'restaurantType':
			restaurantTypeValue = ''
			restaurantTypeResponse = p.getEstablishments(city_id = '4')
			for num, establishment in enumerate(restaurantTypeResponse['establishments']):
				if establishment['establishment']['name'] == searchKeyWord:
					restaurantTypeValue = establishment['establishment']['id']
			response = p.search(entity_type="city", entity_id='4', establishment_type=restaurantTypeValue)
		if searchCategory == 'restaurantCategory':
			category_id = ''
			category_response = p.getCategories()
			for num, category in enumerate(category_response['categories']):
				if category['categories']['name'] == searchKeyWord:
					category_id = category['categories']['id']
			response = p.search(entity_type="city", entity_id='4', category=category_id)
	except Exception as e:
		print(e)
	try:
		for num, restaurant in enumerate(response['restaurants']):
			number= num+1,
			name=restaurant['restaurant']['name']
			name = name.format()
			url=restaurant['restaurant']['url']
			cuisines=restaurant['restaurant']['cuisines']
			rating=restaurant['restaurant']['user_rating']['aggregate_rating']
			icon=restaurant['restaurant']['thumb']
			price=restaurant['restaurant']['average_cost_for_two']
			res_id=restaurant['restaurant']['id']
			dictlist = [dict() for x in range(9)]
			dictlist={'number':number, 'name':name, 'url':url, 'cuisines':cuisines, 'rating':rating, 'icon':icon, 'price':price, 'res_id':res_id }
			list.append(dictlist)
	except Exception as e:
		print(e)
	return render(request, 'home.html', {'context': list})
コード例 #2
0
import pprint
from pyzomato import Pyzomato
pp = pprint.PrettyPrinter(indent=2)

p = Pyzomato("aa2e170fced5e4de42b96789a76fbd7f")
p.search(q="las vegas")

categories = p.getCategories()
pp.pprint( categories )

dets = p.getCollectionsViaCityId(282)
pp.pprint( dets )

cus = p.getCuisines(282)
pp.pprint( cus )

estab = p.getEstablishments(282)
pp.pprint( estab )

#need resturant ID
menu = p.getDailyMenu(292)
pp.pprint( menu )

#need resturant ID
info = p.getRestaurantDetails(292)
pp.pprint( info )

#need resturant ID
reviews = p.getRestaurantReviews(291)
pp.pprint( reviews )