diff --git a/tests/test_parser.py b/tests/test_parser.py index ca0254d..029ea0f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -294,56 +294,3 @@ async def test_issue_28(): assert doc.quotedTweet.id != doc.id check_tweet(doc.quotedTweet) assert doc.quotedTweet.viewCount is not None - - -async def main(): - # prepare mock files from real twitter replies - # you need to have some account to perform this - FRESH = False - - pool = AccountsPool() - api = API(pool) - - jobs = [ - (Files.search_raw, lambda: api.search_raw("elon musk lang:en", limit=20)), - (Files.user_by_id_raw, lambda: api.user_by_id_raw(2244994945)), - (Files.user_by_login_raw, lambda: api.user_by_login_raw("twitterdev")), - (Files.tweet_details_raw, lambda: api.tweet_details_raw(1649191520250245121)), - (Files.followers_raw, lambda: api.followers_raw(2244994945)), - (Files.following_raw, lambda: api.following_raw(2244994945)), - (Files.retweeters_raw, lambda: api.retweeters_raw(1649191520250245121)), - (Files.favoriters_raw, lambda: api.favoriters_raw(1649191520250245121)), - (Files.user_tweets_raw, lambda: api.user_tweets_raw(2244994945)), - (Files.user_tweets_and_replies_raw, lambda: api.user_tweets_and_replies_raw(2244994945)), - ] - - for filename, fn in jobs: - filename = os.path.join(DATA_DIR, f"{filename}") - print("-" * 20) - if os.path.exists(filename) and FRESH is False: - print(f"File {filename} already exists") - continue - - print(f"Getting data for {filename}") - - rep = fn() - is_coroutine = getattr(rep, "__aiter__", None) is None - - data = None - if is_coroutine: - data = await rep - else: - async for x in rep: - data = x - break - - if data is None: - print(f"Failed to get data for {filename}") - continue - - with open(filename, "w") as fp: - fp.write(data.text) - - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/twscrape/db.py b/twscrape/db.py index e7fb6f4..6e3042d 100644 --- a/twscrape/db.py +++ b/twscrape/db.py @@ -78,7 +78,7 @@ async def migrate(db: aiosqlite.Connection): 3: v3, } - logger.debug(f"Current migration v{uv} (latest v{len(migrations)})") + # logger.debug(f"Current migration v{uv} (latest v{len(migrations)})") for i in range(uv + 1, len(migrations) + 1): logger.info(f"Running migration to v{i}") try: diff --git a/twscrape/utils.py b/twscrape/utils.py index a347058..2e1f030 100644 --- a/twscrape/utils.py +++ b/twscrape/utils.py @@ -193,6 +193,9 @@ def parse_cookies(val: str) -> dict[str, str]: try: try: res = json.loads(val) + if isinstance(res, dict) and "cookies" in res: + res = res["cookies"] + if isinstance(res, list): return {x["name"]: x["value"] for x in res} if isinstance(res, dict):