Because Yelp limits the output of businesses to 50, I'm trying to loop through the Census block centroid longitudes and latitudes of San Diego to get all the different businesses (which I want for a project). However, the query does not seem to accept anything that is not strictly numeric. Am I missing something?
Here is my code:
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
yelp_api_key = 'xxx'
#define headers
header = {'Authorization': 'bearer {}'.format(yelp_api_key),
'Content-Type': 'application/json'}
#url = "https://api.yelp.com/v3/businesses/search?location=san%2520diego&sort_by=best_match&limit=20"
append_data = []
for i in range(0,len(bcx)):
#PARAMETERS = {'limit': 50,
# 'offset': 0,
# 'longitude': bcx[i],
# 'latitude': bcy[i]
# }
#build request framework
transport = RequestsHTTPTransport(url = 'https://api.yelp.com/v3/graphql', headers = header, use_json = True) #params = PARAMETERS
# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)
# Provide a GraphQL query
query_bus = gql("""
{
sd_businesses: search(location: "san diego", limit: 50,
offset: 0,
longitude: bcx[i],
latitude: bcy[i]){
total
business {
name
coordinates{
latitude
longitude
}
}
}
}
""")
# Execute the query on the transport
result_bus = client.execute(query_bus)
append_data.append(result_bus)
print(append_data)