Last active
May 3, 2021 14:40
-
-
Save osharaki/8290dd0a1b1e847caa6024740c0739a5 to your computer and use it in GitHub Desktop.
Unogs API miner: main execution task (snippet 3/6)
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
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