Last active
April 25, 2020 03:41
-
-
Save ShayanRiyaz/2a25f3365cc540fea8fe3f65134960df to your computer and use it in GitHub Desktop.
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
def get_neighbourhood_Greek_Restaurant(url1): | |
results = requests.get(url1).json() | |
# assign relevant part of JSON to venues | |
venues = results['response']['venues'] | |
# tranform venues into a data frame | |
dataframe = json_normalize(venues) | |
#print('DataFrame',dataframe) | |
# keep only columns that include venue name, and anything that is associated with location | |
filtered_columns = ['name', 'categories'] + [col for col in dataframe.columns if col.startswith('location.')] + ['id'] | |
#print('Filtered columns',filtered_columns) | |
dataframe_filtered = dataframe.loc[:, filtered_columns] | |
# filter the category for each row | |
dataframe_filtered['categories'] = dataframe_filtered.apply(get_category_type, axis=1) | |
# clean column names by keeping only last term | |
dataframe_filtered.columns = [column.split('.')[-1] for column in dataframe_filtered.columns] | |
display(dataframe_filtered.loc[:,['name','categories','distance','lat','lng']]) | |
category='4bf58dd8d48988d10e941735'#The category for Greek restaurants obtained from https://developer.foursquare.com/docs/resources/categories | |
radius = 700 | |
LIMIT=30 | |
for n in range(0,len(filtered_nhoods)): | |
url = 'http://api.foursquare.com/v2/venues/search?client_id={}&client_secret={}&ll={},{}&v={}&categoryId={}&radius={}&limit={}'.format( | |
CLIENT_ID, | |
CLIENT_SECRET, | |
filtered_nhoods.iloc[n,1], | |
filtered_nhoods.iloc[n,2], | |
VERSION, | |
category, | |
radius, | |
LIMIT) | |
print('------------------------------------------------- '+ filtered_nhoods.iloc[n,0] + ' -------------------------------------------------') | |
get_neighbourhood_Greek_Restaurant(url) | |
print('\n\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment