This is a simple exercise to show you how we use Python to do what we did with a text editor and OpenRefine


In [1]:
#add your client_id here
client_id = '3OSP0BXNUTQTCKT1GVUMVHEUHLY5Y1TVC14CHOU1OOONTLPA'
#add your client_secret here
client_secret = 'J1SG3PYQ21FBYE4KCOS11ATOHGOJJSFAF53F3OFRB54IVTIF'

In [2]:
client_id


Out[2]:
'3OSP0BXNUTQTCKT1GVUMVHEUHLY5Y1TVC14CHOU1OOONTLPA'

Here are the API query elements from our previous request


In [3]:
service = 'https://api.foursquare.com/v2/venues/search?'
ll='40.7037253789768,-74.0079939173954'
radius = '100'
limit = '10'
v = '20140609'

Now we stitch them together to a URL string


In [4]:
url = service + 'll=' + ll + '&radius=' + radius + '&limit=' + limit + '&client_id=' + client_id + '&client_secret=' + client_secret + '&v=' + v

Test the result


In [5]:
print url


https://api.foursquare.com/v2/venues/search?ll=40.7037253789768,-74.0079939173954&radius=100&limit=10&client_id=3OSP0BXNUTQTCKT1GVUMVHEUHLY5Y1TVC14CHOU1OOONTLPA&client_secret=J1SG3PYQ21FBYE4KCOS11ATOHGOJJSFAF53F3OFRB54IVTIF&v=20140609

Requests package for executing web requests ('HTTP for Humans')


In [6]:
import requests

Now we can use the requests package to load the result into Python


In [7]:
r = requests.get(url)

In [8]:
r.content #the result as a string


Out[8]:
'{"meta":{"code":200,"requestId":"5638ed0b498e0990c88b5b19"},"response":{"venues":[{"id":"4a3bbd58f964a520b7a01fe3","name":"Elevated Acre","contact":{},"location":{"address":"55 Water St","lat":40.70326926503271,"lng":-74.00871276855469,"distance":79,"postalCode":"10041","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["55 Water St","New York, NY 10041","United States"]},"categories":[{"id":"4bf58dd8d48988d164941735","name":"Plaza","pluralName":"Plazas","shortName":"Plaza","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/parks_outdoors\\/plaza_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":4202,"usersCount":1712,"tipCount":45},"specials":{"count":0,"items":[]},"hereNow":{"count":1,"summary":"One other person is here","groups":[{"type":"others","name":"Other people here","count":1,"items":[]}]},"referralId":"v-1446571275","venueChains":[]},{"id":"4b423678f964a52016cf25e3","name":"32 Old Slip","contact":{},"location":{"address":"32 Old Slip","lat":40.70363589496425,"lng":-74.00801537138524,"distance":10,"postalCode":"10005","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["32 Old Slip","New York, NY 10005","United States"]},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Office","pluralName":"Offices","shortName":"Office","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/default_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":3290,"usersCount":492,"tipCount":2},"specials":{"count":0,"items":[]},"hereNow":{"count":0,"summary":"Nobody here","groups":[]},"referralId":"v-1446571275","venueChains":[]},{"id":"4dd3c987b0fbf653b64518c6","name":"77 Water Street","contact":{},"location":{"address":"77 Water St","lat":40.70446196748607,"lng":-74.00826786069122,"distance":85,"postalCode":"10005","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["77 Water St","New York, NY 10005","United States"]},"categories":[{"id":"4bf58dd8d48988d130941735","name":"Building","pluralName":"Buildings","shortName":"Building","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/default_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":1818,"usersCount":363,"tipCount":4},"specials":{"count":0,"items":[]},"hereNow":{"count":1,"summary":"One other person is here","groups":[{"type":"others","name":"Other people here","count":1,"items":[]}]},"referralId":"v-1446571275","venueChains":[]},{"id":"4b4222f1f964a52067cd25e3","name":"S&P Capital IQ","contact":{"twitter":"spcapitaliq","facebook":"115155729664","facebookUsername":"spcapitaliq","facebookName":"S&P Capital IQ"},"location":{"address":"55 Water St","crossStreet":"Hanover Square","lat":40.70344820178768,"lng":-74.00976419448853,"distance":152,"postalCode":"10041","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["55 Water St (Hanover Square)","New York, NY 10041","United States"]},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Office","pluralName":"Offices","shortName":"Office","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/default_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":3973,"usersCount":191,"tipCount":2},"url":"http:\\/\\/www.capitaliq.com","specials":{"count":0,"items":[]},"hereNow":{"count":1,"summary":"One other person is here","groups":[{"type":"others","name":"Other people here","count":1,"items":[]}]},"referralId":"v-1446571275","venueChains":[]},{"id":"5154a3e2e4b0ba23c2fbf0f0","name":"Convene at 32 Old Slip","contact":{"phone":"6468547951","formattedPhone":"(646) 854-7951","twitter":"convene","facebook":"112466475508149","facebookUsername":"AtConvene","facebookName":"Convene"},"location":{"address":"32 Old Slip","crossStreet":"at Front Street","lat":40.70351962505307,"lng":-74.00772845131473,"distance":32,"postalCode":"10005","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["32 Old Slip (at Front Street)","New York, NY 10005","United States"]},"categories":[{"id":"4bf58dd8d48988d100941735","name":"Meeting Room","pluralName":"Meeting Rooms","shortName":"Meeting Room","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/conventioncenter_meetingroom_","suffix":".png"},"primary":true}],"verified":true,"stats":{"checkinsCount":513,"usersCount":374,"tipCount":2},"url":"http:\\/\\/convene.com","specials":{"count":0,"items":[]},"storeId":"","hereNow":{"count":0,"summary":"Nobody here","groups":[]},"referralId":"v-1446571275","venueChains":[]},{"id":"4f15a0dce4b06c588eb33a45","name":"Arup","contact":{"twitter":"arupgroup"},"location":{"address":"77 Water St","lat":40.70426494869869,"lng":-74.00843427391516,"distance":70,"postalCode":"10005","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["77 Water St","New York, NY 10005","United States"]},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Office","pluralName":"Offices","shortName":"Office","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/default_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":402,"usersCount":103,"tipCount":0},"url":"http:\\/\\/www.arup.com","specials":{"count":0,"items":[]},"hereNow":{"count":1,"summary":"One other person is here","groups":[{"type":"others","name":"Other people here","count":1,"items":[]}]},"referralId":"v-1446571275","venueChains":[]},{"id":"4c166bc9b7b9c928526dae37","name":"Hudson River Trading LLC","contact":{"phone":"2122931444","formattedPhone":"(212) 293-1444"},"location":{"address":"32 Old Slip, 30th floor","crossStreet":"Front St.","lat":40.70358802343914,"lng":-74.00825064552185,"distance":26,"postalCode":"10005","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["32 Old Slip, 30th floor (Front St.)","New York, NY 10005","United States"]},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Office","pluralName":"Offices","shortName":"Office","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/default_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":338,"usersCount":17,"tipCount":0},"specials":{"count":0,"items":[]},"hereNow":{"count":0,"summary":"Nobody here","groups":[]},"referralId":"v-1446571275","venueChains":[]},{"id":"4b014ad3f964a520fd4122e3","name":"55 Water","contact":{},"location":{"address":"55 Water St","lat":40.70342202788766,"lng":-74.00954751727433,"distance":135,"postalCode":"10041","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["55 Water St","New York, NY 10041","United States"]},"categories":[{"id":"4bf58dd8d48988d130941735","name":"Building","pluralName":"Buildings","shortName":"Building","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/default_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":8961,"usersCount":1108,"tipCount":7},"specials":{"count":0,"items":[]},"hereNow":{"count":0,"summary":"Nobody here","groups":[]},"referralId":"v-1446571275","venueChains":[]},{"id":"4dda9577d4c05d509733f4bd","name":"Bongo Brothers","contact":{"phone":"3477948223","formattedPhone":"(347) 794-8223","twitter":"bongobros"},"location":{"lat":40.70352953651739,"lng":-74.00847673416138,"distance":46,"postalCode":"10011","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["New York, NY 10011","United States"]},"categories":[{"id":"4bf58dd8d48988d1cb941735","name":"Food Truck","pluralName":"Food Trucks","shortName":"Food Truck","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/food\\/streetfood_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":740,"usersCount":472,"tipCount":11},"allowMenuUrlEdit":true,"specials":{"count":0,"items":[]},"hereNow":{"count":0,"summary":"Nobody here","groups":[]},"referralId":"v-1446571275","venueChains":[]},{"id":"4b58f3adf964a520107528e3","name":"the cementbloc","contact":{"phone":"2125246200","formattedPhone":"(212) 524-6200","twitter":"thecementbloc"},"location":{"address":"641 Avenue of the Americas","crossStreet":"at 20th St.","lat":40.703716606018794,"lng":-74.00779008865356,"distance":17,"postalCode":"10011","cc":"US","city":"New York","state":"NY","country":"United States","formattedAddress":["641 Avenue of the Americas (at 20th St.)","New York, NY 10011","United States"]},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Office","pluralName":"Offices","shortName":"Office","icon":{"prefix":"https:\\/\\/ss3.4sqi.net\\/img\\/categories_v2\\/building\\/default_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":749,"usersCount":70,"tipCount":2},"specials":{"count":0,"items":[]},"hereNow":{"count":0,"summary":"Nobody here","groups":[]},"referralId":"v-1446571275","venueChains":[]}],"confident":false}}'

In [9]:
r.json() #the result formatted as JSON


Out[9]:
{u'meta': {u'code': 200, u'requestId': u'5638ed0b498e0990c88b5b19'},
 u'response': {u'confident': False,
  u'venues': [{u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/parks_outdoors/plaza_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d164941735',
      u'name': u'Plaza',
      u'pluralName': u'Plazas',
      u'primary': True,
      u'shortName': u'Plaza'}],
    u'contact': {},
    u'hereNow': {u'count': 1,
     u'groups': [{u'count': 1,
       u'items': [],
       u'name': u'Other people here',
       u'type': u'others'}],
     u'summary': u'One other person is here'},
    u'id': u'4a3bbd58f964a520b7a01fe3',
    u'location': {u'address': u'55 Water St',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'distance': 79,
     u'formattedAddress': [u'55 Water St',
      u'New York, NY 10041',
      u'United States'],
     u'lat': 40.70326926503271,
     u'lng': -74.00871276855469,
     u'postalCode': u'10041',
     u'state': u'NY'},
    u'name': u'Elevated Acre',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 4202, u'tipCount': 45, u'usersCount': 1712},
    u'venueChains': [],
    u'verified': False},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d124941735',
      u'name': u'Office',
      u'pluralName': u'Offices',
      u'primary': True,
      u'shortName': u'Office'}],
    u'contact': {},
    u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
    u'id': u'4b423678f964a52016cf25e3',
    u'location': {u'address': u'32 Old Slip',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'distance': 10,
     u'formattedAddress': [u'32 Old Slip',
      u'New York, NY 10005',
      u'United States'],
     u'lat': 40.70363589496425,
     u'lng': -74.00801537138524,
     u'postalCode': u'10005',
     u'state': u'NY'},
    u'name': u'32 Old Slip',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 3290, u'tipCount': 2, u'usersCount': 492},
    u'venueChains': [],
    u'verified': False},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d130941735',
      u'name': u'Building',
      u'pluralName': u'Buildings',
      u'primary': True,
      u'shortName': u'Building'}],
    u'contact': {},
    u'hereNow': {u'count': 1,
     u'groups': [{u'count': 1,
       u'items': [],
       u'name': u'Other people here',
       u'type': u'others'}],
     u'summary': u'One other person is here'},
    u'id': u'4dd3c987b0fbf653b64518c6',
    u'location': {u'address': u'77 Water St',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'distance': 85,
     u'formattedAddress': [u'77 Water St',
      u'New York, NY 10005',
      u'United States'],
     u'lat': 40.70446196748607,
     u'lng': -74.00826786069122,
     u'postalCode': u'10005',
     u'state': u'NY'},
    u'name': u'77 Water Street',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 1818, u'tipCount': 4, u'usersCount': 363},
    u'venueChains': [],
    u'verified': False},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d124941735',
      u'name': u'Office',
      u'pluralName': u'Offices',
      u'primary': True,
      u'shortName': u'Office'}],
    u'contact': {u'facebook': u'115155729664',
     u'facebookName': u'S&P Capital IQ',
     u'facebookUsername': u'spcapitaliq',
     u'twitter': u'spcapitaliq'},
    u'hereNow': {u'count': 1,
     u'groups': [{u'count': 1,
       u'items': [],
       u'name': u'Other people here',
       u'type': u'others'}],
     u'summary': u'One other person is here'},
    u'id': u'4b4222f1f964a52067cd25e3',
    u'location': {u'address': u'55 Water St',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'crossStreet': u'Hanover Square',
     u'distance': 152,
     u'formattedAddress': [u'55 Water St (Hanover Square)',
      u'New York, NY 10041',
      u'United States'],
     u'lat': 40.70344820178768,
     u'lng': -74.00976419448853,
     u'postalCode': u'10041',
     u'state': u'NY'},
    u'name': u'S&P Capital IQ',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 3973, u'tipCount': 2, u'usersCount': 191},
    u'url': u'http://www.capitaliq.com',
    u'venueChains': [],
    u'verified': False},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/conventioncenter_meetingroom_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d100941735',
      u'name': u'Meeting Room',
      u'pluralName': u'Meeting Rooms',
      u'primary': True,
      u'shortName': u'Meeting Room'}],
    u'contact': {u'facebook': u'112466475508149',
     u'facebookName': u'Convene',
     u'facebookUsername': u'AtConvene',
     u'formattedPhone': u'(646) 854-7951',
     u'phone': u'6468547951',
     u'twitter': u'convene'},
    u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
    u'id': u'5154a3e2e4b0ba23c2fbf0f0',
    u'location': {u'address': u'32 Old Slip',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'crossStreet': u'at Front Street',
     u'distance': 32,
     u'formattedAddress': [u'32 Old Slip (at Front Street)',
      u'New York, NY 10005',
      u'United States'],
     u'lat': 40.70351962505307,
     u'lng': -74.00772845131473,
     u'postalCode': u'10005',
     u'state': u'NY'},
    u'name': u'Convene at 32 Old Slip',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 513, u'tipCount': 2, u'usersCount': 374},
    u'storeId': u'',
    u'url': u'http://convene.com',
    u'venueChains': [],
    u'verified': True},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d124941735',
      u'name': u'Office',
      u'pluralName': u'Offices',
      u'primary': True,
      u'shortName': u'Office'}],
    u'contact': {u'twitter': u'arupgroup'},
    u'hereNow': {u'count': 1,
     u'groups': [{u'count': 1,
       u'items': [],
       u'name': u'Other people here',
       u'type': u'others'}],
     u'summary': u'One other person is here'},
    u'id': u'4f15a0dce4b06c588eb33a45',
    u'location': {u'address': u'77 Water St',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'distance': 70,
     u'formattedAddress': [u'77 Water St',
      u'New York, NY 10005',
      u'United States'],
     u'lat': 40.70426494869869,
     u'lng': -74.00843427391516,
     u'postalCode': u'10005',
     u'state': u'NY'},
    u'name': u'Arup',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 402, u'tipCount': 0, u'usersCount': 103},
    u'url': u'http://www.arup.com',
    u'venueChains': [],
    u'verified': False},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d124941735',
      u'name': u'Office',
      u'pluralName': u'Offices',
      u'primary': True,
      u'shortName': u'Office'}],
    u'contact': {u'formattedPhone': u'(212) 293-1444',
     u'phone': u'2122931444'},
    u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
    u'id': u'4c166bc9b7b9c928526dae37',
    u'location': {u'address': u'32 Old Slip, 30th floor',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'crossStreet': u'Front St.',
     u'distance': 26,
     u'formattedAddress': [u'32 Old Slip, 30th floor (Front St.)',
      u'New York, NY 10005',
      u'United States'],
     u'lat': 40.70358802343914,
     u'lng': -74.00825064552185,
     u'postalCode': u'10005',
     u'state': u'NY'},
    u'name': u'Hudson River Trading LLC',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 338, u'tipCount': 0, u'usersCount': 17},
    u'venueChains': [],
    u'verified': False},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d130941735',
      u'name': u'Building',
      u'pluralName': u'Buildings',
      u'primary': True,
      u'shortName': u'Building'}],
    u'contact': {},
    u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
    u'id': u'4b014ad3f964a520fd4122e3',
    u'location': {u'address': u'55 Water St',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'distance': 135,
     u'formattedAddress': [u'55 Water St',
      u'New York, NY 10041',
      u'United States'],
     u'lat': 40.70342202788766,
     u'lng': -74.00954751727433,
     u'postalCode': u'10041',
     u'state': u'NY'},
    u'name': u'55 Water',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 8961, u'tipCount': 7, u'usersCount': 1108},
    u'venueChains': [],
    u'verified': False},
   {u'allowMenuUrlEdit': True,
    u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/food/streetfood_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d1cb941735',
      u'name': u'Food Truck',
      u'pluralName': u'Food Trucks',
      u'primary': True,
      u'shortName': u'Food Truck'}],
    u'contact': {u'formattedPhone': u'(347) 794-8223',
     u'phone': u'3477948223',
     u'twitter': u'bongobros'},
    u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
    u'id': u'4dda9577d4c05d509733f4bd',
    u'location': {u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'distance': 46,
     u'formattedAddress': [u'New York, NY 10011', u'United States'],
     u'lat': 40.70352953651739,
     u'lng': -74.00847673416138,
     u'postalCode': u'10011',
     u'state': u'NY'},
    u'name': u'Bongo Brothers',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 740, u'tipCount': 11, u'usersCount': 472},
    u'venueChains': [],
    u'verified': False},
   {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
       u'suffix': u'.png'},
      u'id': u'4bf58dd8d48988d124941735',
      u'name': u'Office',
      u'pluralName': u'Offices',
      u'primary': True,
      u'shortName': u'Office'}],
    u'contact': {u'formattedPhone': u'(212) 524-6200',
     u'phone': u'2125246200',
     u'twitter': u'thecementbloc'},
    u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
    u'id': u'4b58f3adf964a520107528e3',
    u'location': {u'address': u'641 Avenue of the Americas',
     u'cc': u'US',
     u'city': u'New York',
     u'country': u'United States',
     u'crossStreet': u'at 20th St.',
     u'distance': 17,
     u'formattedAddress': [u'641 Avenue of the Americas (at 20th St.)',
      u'New York, NY 10011',
      u'United States'],
     u'lat': 40.703716606018794,
     u'lng': -74.00779008865356,
     u'postalCode': u'10011',
     u'state': u'NY'},
    u'name': u'the cementbloc',
    u'referralId': u'v-1446571275',
    u'specials': {u'count': 0, u'items': []},
    u'stats': {u'checkinsCount': 749, u'tipCount': 2, u'usersCount': 70},
    u'venueChains': [],
    u'verified': False}]}}

This is formatted as a dictionary


In [10]:
venues = r.json()['response']['venues']

In [43]:
venues


Out[43]:
[{u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d124941735',
    u'name': u'Office',
    u'pluralName': u'Offices',
    u'primary': True,
    u'shortName': u'Office'}],
  u'contact': {},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4b423678f964a52016cf25e3',
  u'location': {u'address': u'32 Old Slip',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'distance': 10,
   u'formattedAddress': [u'32 Old Slip',
    u'New York, NY 10005',
    u'United States'],
   u'lat': 40.70363589496425,
   u'lng': -74.00801537138524,
   u'postalCode': u'10005',
   u'state': u'NY'},
  u'name': u'32 Old Slip',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 3290, u'tipCount': 2, u'usersCount': 492},
  u'venueChains': [],
  u'verified': False},
 {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/conventioncenter_meetingroom_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d100941735',
    u'name': u'Meeting Room',
    u'pluralName': u'Meeting Rooms',
    u'primary': True,
    u'shortName': u'Meeting Room'}],
  u'contact': {u'facebook': u'112466475508149',
   u'facebookName': u'Convene',
   u'facebookUsername': u'AtConvene',
   u'formattedPhone': u'(646) 854-7951',
   u'phone': u'6468547951',
   u'twitter': u'convene'},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'5154a3e2e4b0ba23c2fbf0f0',
  u'location': {u'address': u'32 Old Slip',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'crossStreet': u'at Front Street',
   u'distance': 32,
   u'formattedAddress': [u'32 Old Slip (at Front Street)',
    u'New York, NY 10005',
    u'United States'],
   u'lat': 40.70351962505307,
   u'lng': -74.00772845131473,
   u'postalCode': u'10005',
   u'state': u'NY'},
  u'name': u'Convene at 32 Old Slip',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 511, u'tipCount': 2, u'usersCount': 374},
  u'storeId': u'',
  u'url': u'http://convene.com',
  u'venueChains': [],
  u'verified': True},
 {u'allowMenuUrlEdit': True,
  u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/shops/pharmacy_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d10f951735',
    u'name': u'Drugstore / Pharmacy',
    u'pluralName': u'Drugstores / Pharmacies',
    u'primary': True,
    u'shortName': u'Pharmacy'}],
  u'contact': {u'facebook': u'94117394603',
   u'facebookName': u'Duane Reade',
   u'facebookUsername': u'duanereade',
   u'formattedPhone': u'(212) 363-5830',
   u'phone': u'2123635830',
   u'twitter': u'duanereade'},
  u'hereNow': {u'count': 1,
   u'groups': [{u'count': 1,
     u'items': [],
     u'name': u'Other people here',
     u'type': u'others'}],
   u'summary': u'One other person is here'},
  u'id': u'4ba57508f964a520160939e3',
  u'location': {u'address': u'95 Wall St',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'crossStreet': u'btwn Wall St & Gouverneur Ln',
   u'distance': 109,
   u'formattedAddress': [u'95 Wall St (btwn Wall St & Gouverneur Ln)',
    u'New York, NY 10005',
    u'United States'],
   u'lat': 40.70469261228684,
   u'lng': -74.0077793598175,
   u'postalCode': u'10005',
   u'state': u'NY'},
  u'name': u'Duane Reade',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 2798, u'tipCount': 7, u'usersCount': 962},
  u'storeId': u'14126',
  u'url': u'http://www.duanereade.com',
  u'venueChains': [{u'id': u'556c9990a7c87f637869a5fd'}],
  u'verified': True},
 {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d124941735',
    u'name': u'Office',
    u'pluralName': u'Offices',
    u'primary': True,
    u'shortName': u'Office'}],
  u'contact': {u'facebook': u'115155729664',
   u'facebookName': u'S&P Capital IQ',
   u'facebookUsername': u'spcapitaliq',
   u'twitter': u'spcapitaliq'},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4b4222f1f964a52067cd25e3',
  u'location': {u'address': u'55 Water St',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'crossStreet': u'Hanover Square',
   u'distance': 152,
   u'formattedAddress': [u'55 Water St (Hanover Square)',
    u'New York, NY 10041',
    u'United States'],
   u'lat': 40.70344820178768,
   u'lng': -74.00976419448853,
   u'postalCode': u'10041',
   u'state': u'NY'},
  u'name': u'S&P Capital IQ',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 3971, u'tipCount': 2, u'usersCount': 191},
  u'url': u'http://www.capitaliq.com',
  u'venueChains': [],
  u'verified': False},
 {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/parks_outdoors/plaza_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d164941735',
    u'name': u'Plaza',
    u'pluralName': u'Plazas',
    u'primary': True,
    u'shortName': u'Plaza'}],
  u'contact': {},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4a3bbd58f964a520b7a01fe3',
  u'location': {u'address': u'55 Water St',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'distance': 79,
   u'formattedAddress': [u'55 Water St',
    u'New York, NY 10041',
    u'United States'],
   u'lat': 40.70326926503271,
   u'lng': -74.00871276855469,
   u'postalCode': u'10041',
   u'state': u'NY'},
  u'name': u'Elevated Acre',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 4201, u'tipCount': 45, u'usersCount': 1712},
  u'venueChains': [],
  u'verified': False},
 {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d130941735',
    u'name': u'Building',
    u'pluralName': u'Buildings',
    u'primary': True,
    u'shortName': u'Building'}],
  u'contact': {},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4dd3c987b0fbf653b64518c6',
  u'location': {u'address': u'77 Water St',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'distance': 85,
   u'formattedAddress': [u'77 Water St',
    u'New York, NY 10005',
    u'United States'],
   u'lat': 40.70446196748607,
   u'lng': -74.00826786069122,
   u'postalCode': u'10005',
   u'state': u'NY'},
  u'name': u'77 Water Street',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 1817, u'tipCount': 4, u'usersCount': 363},
  u'venueChains': [],
  u'verified': False},
 {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d124941735',
    u'name': u'Office',
    u'pluralName': u'Offices',
    u'primary': True,
    u'shortName': u'Office'}],
  u'contact': {u'formattedPhone': u'(212) 293-1444', u'phone': u'2122931444'},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4c166bc9b7b9c928526dae37',
  u'location': {u'address': u'32 Old Slip, 30th floor',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'crossStreet': u'Front St.',
   u'distance': 26,
   u'formattedAddress': [u'32 Old Slip, 30th floor (Front St.)',
    u'New York, NY 10005',
    u'United States'],
   u'lat': 40.70358802343914,
   u'lng': -74.00825064552185,
   u'postalCode': u'10005',
   u'state': u'NY'},
  u'name': u'Hudson River Trading LLC',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 338, u'tipCount': 0, u'usersCount': 17},
  u'venueChains': [],
  u'verified': False},
 {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d130941735',
    u'name': u'Building',
    u'pluralName': u'Buildings',
    u'primary': True,
    u'shortName': u'Building'}],
  u'contact': {},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4b014ad3f964a520fd4122e3',
  u'location': {u'address': u'55 Water St',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'distance': 135,
   u'formattedAddress': [u'55 Water St',
    u'New York, NY 10041',
    u'United States'],
   u'lat': 40.70342202788766,
   u'lng': -74.00954751727433,
   u'postalCode': u'10041',
   u'state': u'NY'},
  u'name': u'55 Water',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 8961, u'tipCount': 7, u'usersCount': 1108},
  u'venueChains': [],
  u'verified': False},
 {u'allowMenuUrlEdit': True,
  u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/food/streetfood_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d1cb941735',
    u'name': u'Food Truck',
    u'pluralName': u'Food Trucks',
    u'primary': True,
    u'shortName': u'Food Truck'}],
  u'contact': {u'formattedPhone': u'(347) 794-8223',
   u'phone': u'3477948223',
   u'twitter': u'bongobros'},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4dda9577d4c05d509733f4bd',
  u'location': {u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'distance': 46,
   u'formattedAddress': [u'New York, NY 10011', u'United States'],
   u'lat': 40.70352953651739,
   u'lng': -74.00847673416138,
   u'postalCode': u'10011',
   u'state': u'NY'},
  u'name': u'Bongo Brothers',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 740, u'tipCount': 11, u'usersCount': 472},
  u'venueChains': [],
  u'verified': False},
 {u'categories': [{u'icon': {u'prefix': u'https://ss3.4sqi.net/img/categories_v2/building/default_',
     u'suffix': u'.png'},
    u'id': u'4bf58dd8d48988d124941735',
    u'name': u'Office',
    u'pluralName': u'Offices',
    u'primary': True,
    u'shortName': u'Office'}],
  u'contact': {u'formattedPhone': u'(212) 524-6200',
   u'phone': u'2125246200',
   u'twitter': u'thecementbloc'},
  u'hereNow': {u'count': 0, u'groups': [], u'summary': u'Nobody here'},
  u'id': u'4b58f3adf964a520107528e3',
  u'location': {u'address': u'641 Avenue of the Americas',
   u'cc': u'US',
   u'city': u'New York',
   u'country': u'United States',
   u'crossStreet': u'at 20th St.',
   u'distance': 17,
   u'formattedAddress': [u'641 Avenue of the Americas (at 20th St.)',
    u'New York, NY 10011',
    u'United States'],
   u'lat': 40.703716606018794,
   u'lng': -74.00779008865356,
   u'postalCode': u'10011',
   u'state': u'NY'},
  u'name': u'the cementbloc',
  u'referralId': u'v-1446529913',
  u'specials': {u'count': 0, u'items': []},
  u'stats': {u'checkinsCount': 749, u'tipCount': 2, u'usersCount': 70},
  u'venueChains': [],
  u'verified': False}]

In [47]:
for v in venues:
    print v['name'] + ', ' + str(v['location']['lat']) + ', ' + str(v['location']['lng'])


32 Old Slip, 40.703635895, -74.0080153714
Convene at 32 Old Slip, 40.7035196251, -74.0077284513
Duane Reade, 40.7046926123, -74.0077793598
S&P Capital IQ, 40.7034482018, -74.0097641945
Elevated Acre, 40.703269265, -74.0087127686
77 Water Street, 40.7044619675, -74.0082678607
Hudson River Trading LLC, 40.7035880234, -74.0082506455
55 Water, 40.7034220279, -74.0095475173
Bongo Brothers, 40.7035295365, -74.0084767342
the cementbloc, 40.703716606, -74.0077900887

In [48]:
outputFile = open('4sq_location.csv','w')
outputFile.write('name,latitude,longitude\n')

In [49]:
for v in venues:
    outputFile.write(v['name'] + ', ' + str(v['location']['lat']) + ', ' + str(v['location']['lng']) + '\n')
outputFile.close()

In [ ]: