from yelp.client import Client
from yelp.oauth1_authenticator import Oauth1Authenticator
from yelp.errors import BusinessUnavailable
import os
import json
def import_credentials(filename='../data/yelp_credentials.json'):
try:
data = json.load(open(filename))
return data
except:
raise IOError('This API requires Yelp credentials to work. Did you forget to define them?')
credentials = import_credentials()
auth = Oauth1Authenticator(
consumer_key=credentials['consumer_key'],
consumer_secret=credentials['consumer_secret'],
token=credentials['token'],
token_secret=credentials['token_secret']
)
client = Client(auth)
def yelp(num):
num = int(num)
try:
business = client.phone_search(num).businesses[0]
return {'Yelp Name': business.name,
'Yelp Address': business.location.address,
'Yelp Latitude': business.location.coordinate.latitude,
'Yelp Longitude': business.location.coordinate.longitude}
except IndexError:
return None
import pandas as pd
inspections = pd.read_csv("../data/inspections_flattened_initial.csv", index_col=0)
import numpy as np
yelp(np.nan)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-2-1742ea9d0355> in <module>() 1 import numpy as np ----> 2 yelp(np.nan) <ipython-input-1-b6452e63a2af> in yelp(num) 24 25 def yelp(num): ---> 26 num = int(num) 27 try: 28 business = client.phone_search(num).businesses[0] ValueError: cannot convert float NaN to integer
ex =client.phone_search(int(inspections['DOHMH PHONE'].iloc[0])).businesses[0]
ex.location.cordinate
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-16-90c6c299a614> in <module>() ----> 1 ex.location.cordinate AttributeError: 'Location' object has no attribute 'cordinate'