From a37061a660b769f197e1bfc531469cdd18a0dbef Mon Sep 17 00:00:00 2001 From: fzzinchemical Date: Thu, 13 Nov 2025 12:56:07 +0100 Subject: [PATCH] initial commit --- .gitignore | 2 ++ main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 6 ++++++ 3 files changed, 56 insertions(+) create mode 100644 .gitignore create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c4ffc4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.venv/ \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..f090d00 --- /dev/null +++ b/main.py @@ -0,0 +1,48 @@ +import os +import logging +from dotenv import load_dotenv +from twscrape import API, gather, set_log_level + + +# Configuration +load_dotenv() +OUTPUT_FILE = os.getenv("OUTPUT_FILE", "tweets.json") +SLEEP_MIN = 5 +SLEEP_MAX = 10 +LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper() + +logging.basicConfig(level=LOG_LEVEL, format="%(asctime)s %(levelname)s %(message)s") +logger = logging.getLogger(__name__) + +COOKIES = {} +async def main(): + + api = API() # or API("path-to.db") – default is `accounts.db` + + # ADD ACCOUNTS (for CLI usage see next readme section) + + # Option 1. Adding account with cookies (more stable) + load_dotenv() + cookies = os.getenv("COOKIES") + await api.pool.add_account("user3", "pass3", "u3@mail.com", "mail_pass3", cookies=cookies) + + await api.pool.login_all() # try to login to receive account cookies + + # NOTE 2: all methods have `raw` version (returns `httpx.Response` object): + async for rep in api.search_raw("elon musk"): + print(rep.status_code, rep.json()) # rep is `httpx.Response` object + + # change log level, default info + set_log_level("DEBUG") + + # Tweet & User model can be converted to regular dict or json, e.g.: + doc = await api.user_by_id(user_id) # User + doc.dict() # -> python dict + doc.json() # -> json string + +if __name__ == "__main__": + asyncio.run(main()) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a2af71f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +requests +python-dotenv +bs4 +httpx +asyncio +twscrape \ No newline at end of file