Skip to content

Commit

Permalink
Catch exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed May 11, 2024
1 parent 4bbccdf commit 8d99057
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions x_notes/tweets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from os import environ
from typing import Any
from twscrape import API
from twscrape import API, NoAccountError
from .github import update_secret
from .helpers import load_notes, save_notes

Expand Down Expand Up @@ -44,27 +44,26 @@ def get_next_unfetched_note(notes: dict[str, dict[str, Any]]) -> dict[str, Any]
return

api = await login()
retry_login = True

while True:
note = get_next_unfetched_note(notes)
if not note:
print("No more tweets to fetch")
break
note_id = note["note_id"]
tweet = await api.tweet_details(int(note["tweet_id"]))
try:
tweet = await api.tweet_details(int(note["tweet_id"]))
except NoAccountError:
print("Rate limited – giving up")
break
account = await api.pool.get(environ["USER"])
if not account.active:
print("Failed to fetch tweet")
if retry_login and environ.get("COOKIES"):
retry_login = False
if environ.get("COOKIES"):
await api.pool.delete_inactive()
del environ["COOKIES"]
api = await login()
continue
else:
print("Rate limited – give up")
break
continue
note["dl"] = 1
if tweet:
note["lang"] = tweet.lang
Expand Down

0 comments on commit 8d99057

Please sign in to comment.