Example #1
0
class ZomotoAPI:
    def __init__(self):

        # Api secret keys stored in enviornment variable

        self.api_key = os.environ.get('api_key')

    def get_Categories(self, citi_id):

        self.api_client_auth = Pyzomato(self.api_key)

        self.api_client_auth.search(name="Chennai")

        # city id for chennai is 7

        return self.api_client_auth.getCategories()

    def search_city_by_geo_code(self, latitude, longitude):

        return self.api_client_auth.getByGeocode(latitude, longitude)

    def locating_res_by_id(self, res_id):

        # id > 18387708
        # name > kakada ramprasad
        # "locality_verbose": "Kilpauk, Chennai"

        return self.api_client_auth.getRestaurantDetails(res_id)
Example #2
0
def get_zomato():
    """
        Function to grab the restaurants from zomato
    """

    # Bing key to standardized the addresses
    bing_key = os.environ.get('BING_API_KEY')
    bing = geocoders.Bing(bing_key)

    # Empty list to add restaurants in
    yelp_params = []

    # Use Pyzomato to make requests to zomato api
    p = Pyzomato(ZOMATO_API_KEY)

    # Location response
    response = (p.getByGeocode(lan="37.792085", lon="-122.399368"))

    # Json response from zomato
    restaurants = (response.get('nearby_restaurants'))

    # Iterate over response and grab necessary information
    for place in restaurants:
        restaurant = {}
        info = place.get('restaurant')
        name = (info.get('name'))
        address = (info.get('location').get('address'))[:-1]
        rating = float(info.get('user_rating').get('aggregate_rating'))
        reviews_count = int(info.get('user_rating').get('votes'))
        restaurant['total_reviews'] = reviews_count
        standardized_rating = round((rating / 5), 2)
        restaurant['standard_rating'] = standardized_rating
        rating_weight = round((reviews_count * 1.35), 2)
        restaurant['rating_weight'] = rating_weight
        price_range = info.get('price_range')
        restaurant['price_range'] = price_range

        # Try to update the location with bing's addesss
        try:
            for place in bing.geocode(address, exactly_one=False, timeout=5):
                location = str(place)
            if location is None:
                restaurant['name'] = name
                restaurant['location'] = address
                yelp_params.append(restaurant)
            else:
                restaurant['name'] = name
                restaurant['location'] = location
                yelp_params.append(restaurant)
        except Exception as e:
            print("ZERROR:", e)
    # Return the completed list
    return yelp_params
Example #3
0
def get_zomato():
    """
        Function to grab the restaurants from zomato
    """

    # Bing key to standardized the addresses
    bing_key = "bNV4gwzuDF0BY7hRBr2D~SwYlwf_NvSxlbZ36oGsTdA~AthfnABkus6e2oSBb4W9Q9_7yHrFh1cHbreVFmsPad2apAgjYqLYZi8E2iSyiJk-"
    bing = geocoders.Bing(bing_key)

    # Empty list to add restaurants in
    yelp_params = []

    # Use Pyzomato to make requests to zomato api
    p = Pyzomato('a27dcc3db4574a4ae90e9852091e736c')

    # Location response
    response = (p.getByGeocode(lan="37.792085", lon="-122.399368"))

    # Json response from zomato
    restaurants = (response.get('nearby_restaurants'))

    # Iterate over response and grab necessary information
    for place in restaurants:
        restaurant = {}
        info = place.get('restaurant')
        name = (info.get('name'))
        address = (info.get('location').get('address'))[:-1]
        rating = float(info.get('user_rating').get('aggregate_rating'))
        reviews_count = int(info.get('user_rating').get('votes'))
        restaurant['total_reviews'] = reviews_count
        standardized_rating = round((rating / 5), 2)
        restaurant['standard_rating'] = standardized_rating
        rating_weight = round((reviews_count * 1.35), 2)
        restaurant['rating_weight'] = rating_weight
        price_range = info.get('price_range')
        restaurant['price_range'] = price_range

        # Try to update the location with bing's addesss
        try:
            for place in bing.geocode(address, exactly_one=False, timeout=5):
                location = str(place)
            if location is None:
                restaurant['name'] = name
                restaurant['location'] = address
                yelp_params.append(restaurant)
            else:
                restaurant['name'] = name
                restaurant['location'] = location
                yelp_params.append(restaurant)
        except Exception as e:
            print("ZERROR:", e)
    # Return the completed list
    return yelp_params
def restaurants():
    address = request.args.get('address')
    if not address:
        return "Bad Request!<br>Address parameter is empty or invalid."
    client = GeocodioClient('e69dd65d59f64d56bb99e5fea55f5b1d999a696')
    zomato = Pyzomato('188eda180987998d1dd37a7b93fee08a')

    location = client.geocode(address) # .coords to get lat and lng right away
    lat = location['results'][0]['location']['lat']     # parsing json
    lng = location['results'][0]['location']['lng']

    zomatoData = zomato.getByGeocode(lat, lng)

    output = {
        'restaurants': []
    }
    for r in zomatoData['nearby_restaurants']:
        output['restaurants'].append(dict({'name': r['restaurant']['name'],
                                           'address': r['restaurant']['location']['address'],
                                           'cuisines:': r['restaurant']['cuisines'],
                                           'rating': r['restaurant']['user_rating']['aggregate_rating']
                                           }))
    print(output)
    return jsonify(output)
Example #5
0
#!/usr/bin/python3
from geopy.geocoders import GoogleV3
from pymongo import MongoClient
import requests, json
from pyzomato import Pyzomato

if __name__ == "__main__":
    zomato_key = "a27dcc3db4574a4ae90e9852091e736c"

    zomato = Pyzomato(zomato_key)
    geolocator = GoogleV3(api_key="AIzaSyDQ-1MWdP4V8LAqo4CJ6t1gHsa0FZos7aI")
    zip_codes = [
        '94130', '94133', '94111', '94123', '94129', '94121', '94118', '94115',
        '94109', '94108', '94104', '94105', '94102', '94103', '94158', '94107',
        '94110', '94114', '94117', '94124', '94134', '94112', '94127', '94131',
        '94116', '94132', '94122'
    ]
    client = MongoClient('mongodb://localhost:27017/')
    db = client.guiscore

    for zip_code in zip_codes:
        address = geolocator.geocode(zip_code, timeout=7)
        response = (zomato.getByGeocode(lan="{}".format(address.latitude),
                                        lon="{}".format(address.longitude)))
        area_stats = response.get('popularity')
        if area_stats is None:
            continue
        print("------Adding Zomato area stats----------", area_stats)
        area_stats.update({'zip_code': '{}'.format(zip_code)})
        db.tips.update({'zip_code': zip_code}, area_stats, upsert=True)