Skip to content

Instantly share code, notes, and snippets.

@tylerknutson
Created August 5, 2016 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerknutson/ea3de365ddaae5d10eb8430e0dc79279 to your computer and use it in GitHub Desktop.
Save tylerknutson/ea3de365ddaae5d10eb8430e0dc79279 to your computer and use it in GitHub Desktop.
Importing JSON data in python
import requests
import json
import time
def getdata(offset_no, t = []):
r1 = np.arange(1,96000,500)
r2 = np.array([0])
r = np.concatenate([r2,r1[1:len(r1)]])
i = offset_no
for i in r[r>=offset_no]:
try:
url = 'http://services.wine.com/api/beta2/service.svc/json/catalog?apikey=KEY&size=500&offset='+str(i)
data = requests.get(url).text
t.append(json.loads(data)) #then need to update t to append the next query result
time.sleep(2)
except Exception as e:
print i
print e
print '_'*60
break
return t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment