forked from juanfrans-courses/api_python_workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_Adding_Points_Python3.py
44 lines (38 loc) · 1.17 KB
/
02_Adding_Points_Python3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
print ('Importing libraries...')
from urllib.request import urlopen, HTTPError
import json
import csv
import time
# Setting up the global variables
clientID = 'your client id here'
clientSecret = 'your client secret here'
lat = 40.7
lon = -74
version = 20161016
baseURL = 'https://api.foursquare.com/v2/venues/search?'
limit = 50
# Open the base CSV file
with open('Base_Points.csv', 'r') as basePoints:
reader = csv.reader(basePoints, delimiter=',')
baseList = list(reader)
# Building the request
for point in baseList[1:10]:
longitude = point[0]
latitude = point[1]
request = baseURL + 'v=' + str(version) + '&ll=' + str(latitude) + ',' + str(longitude) + '&limit=' + str(limit) + '&client_id=' + clientID + '&client_secret=' + clientSecret
# Querying the API
try:
response = urlopen(request)
readResponse = response.read()
decodedResponse = readResponse.decode('utf-8')
baseData = json.loads(decodedResponse)
# Parsing the API
content = baseData['response']
venues = content['venues']
for venue in venues:
venueName = venue['name']
print(venueName)
except HTTPError:
print('There is a problem with the request...')
time.sleep(1)
print ('All done...')