From 45013b9939f88d36c6d58c80cdc1b835c1537b94 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 15 Jul 2023 16:34:28 +0100 Subject: [PATCH] Log rate limit for statistics --- twExtract/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/twExtract/__init__.py b/twExtract/__init__.py index b3cc8b4..9801bbc 100644 --- a/twExtract/__init__.py +++ b/twExtract/__init__.py @@ -119,7 +119,13 @@ def extractStatusV2(url): if tweet.status_code == 429: # try another token continue + try: + rateLimitRemaining = tweet.headers.get("x-rate-limit-remaining") + print(f"Twitter Token Rate limit remaining: {rateLimitRemaining}") + except: # for some reason the header is not always present + pass output = tweet.json() + if "errors" in output: # try another token continue