Skip to content

Commit

Permalink
Prevent timeouts caused by rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
tekktrik committed Feb 13, 2024
1 parent bbdce97 commit 2dfa879
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions scripts/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@
json.dump(json_resp, contribfile)


len_nodes = len(json_resp["repositories"]["nodes"])
for index, node in enumerate(json_resp["repositories"]["nodes"]):
for _ in range(5):
img_resp = requests.get(node["openGraphImageUrl"], timeout=5)
status_okay = 200
if img_resp.status_code == status_okay:
with open(str(new_card_dir / f"card{index}.png"), mode="wb") as imgfile:
for data_chunk in img_resp:
imgfile.write(data_chunk)
else:
time.sleep(2)
for _ in range(3):
try:
img_resp = requests.get(node["openGraphImageUrl"], timeout=10)
status_okay = 200
if img_resp.status_code == status_okay:
with open(str(new_card_dir / f"card{index}.png"), mode="wb") as imgfile:
for data_chunk in img_resp:
imgfile.write(data_chunk)
break
except (TimeoutError, requests.exceptions.ReadTimeout):
pass # Try again
finally:
if index != len_nodes - 1:
time.sleep(1)

0 comments on commit 2dfa879

Please sign in to comment.