Skip to content

Commit

Permalink
refactor: pass API to login
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed May 15, 2024
1 parent 357a526 commit ccbb622
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions x_notes/tweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit ccbb622

Please sign in to comment.