Skip to content

Instantly share code, notes, and snippets.

@osharaki
Last active May 3, 2021 14:40
Show Gist options
  • Save osharaki/8290dd0a1b1e847caa6024740c0739a5 to your computer and use it in GitHub Desktop.
Save osharaki/8290dd0a1b1e847caa6024740c0739a5 to your computer and use it in GitHub Desktop.
Unogs API miner: main execution task (snippet 3/6)
def job():
global remaining_quota
global offset
global done
count = 0
while int(remaining_quota) - buffer > 0:
querystring["offset"] = str(offset)
response = requests.request("GET", url, headers=headers, params=querystring)
if response:
content = response.json()
remaining_quota = int(response.headers["X-RateLimit-Requests-Remaining"])
if "results" in content:
shows = content["results"]
if shows:
count += len(shows)
if "shows" not in data:
data["shows"] = shows
else:
data["shows"] += shows
offset += 100
else: # offset exceeded
done = True
break
else:
done = True # better to stop program and take a look in case of a failed request
break
data["count"] += count
with open("data.json", "w") as f:
json.dump(data, f, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment