Created
August 5, 2016 12:13
-
-
Save tylerknutson/ea3de365ddaae5d10eb8430e0dc79279 to your computer and use it in GitHub Desktop.
Importing JSON data in python
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
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