From ccbb622966007d89d33d4bdc69512e5c6f526593 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Thu, 16 May 2024 00:49:23 +0100 Subject: [PATCH] refactor: pass API to login --- x_notes/tweets.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/x_notes/tweets.py b/x_notes/tweets.py index 68fbb30c..90d68923 100644 --- a/x_notes/tweets.py +++ b/x_notes/tweets.py @@ -14,12 +14,7 @@ def get_next_unfetched_note(notes: dict[str, dict[str, Any]]) -> dict[str, Any] return next((note for note in notes.values() if "dl" not in note), None) -async def login() -> API: - api = API( - proxy=environ.get("TW_PROXY"), - raise_when_no_account=True, - ) - +async def login(api: API) -> None: username = environ["TW_USER"] account_kwargs = { "username": username, @@ -41,7 +36,6 @@ async def login() -> API: if environ.get("GH_UPDATE_SECRET"): logger.info("Updating secret ...") update_secret("COOKIES", json.dumps(account.cookies)) - return api async def fetch_tweets() -> None: @@ -56,6 +50,10 @@ async def fetch_tweets() -> None: tweets_with_multi_notes = get_tweets_with_multi_notes(notes) + api = API( + proxy=environ.get("TW_PROXY"), + raise_when_no_account=True, + ) api = await login() total_fetched = 0 @@ -76,7 +74,7 @@ async def fetch_tweets() -> None: if environ.get("TW_COOKIES"): await api.pool.delete_inactive() del environ["TW_COOKIES"] - api = await login() + await login() continue note_update = { "dl": 1,