From d0fbef5b0c85c0ef3216c75ae17a2214c5933100 Mon Sep 17 00:00:00 2001 From: Vlad Pronsky Date: Wed, 1 Nov 2023 21:31:12 +0200 Subject: [PATCH] update readme on how to change search tab --- Makefile | 1 + readme.md | 2 ++ twscrape/models.py | 33 ++++++++++++++------------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index d7d0427..3000e2f 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,7 @@ test-sq-matrix: @make test-sq y=2020 v=3330000 @make test-sq y=2021 v=3340100 @make test-sq y=2023 v=3430000 + @make test-sq y=2023 v=3440000 update-mocks: twscrape user_by_id --raw 2244994945 | jq > ./tests/mocked-data/user_by_id_raw.json diff --git a/readme.md b/readme.md index 52794b3..b254532 100644 --- a/readme.md +++ b/readme.md @@ -77,6 +77,8 @@ async def main(): # search (latest tab) await gather(api.search("elon musk", limit=20)) # list[Tweet] + # change search tab (product), can be: Top, Latest (default), Media + await gather(api.search("elon musk", limit=20, kv={"product": "Top"})) # tweet info tweet_id = 20 diff --git a/twscrape/models.py b/twscrape/models.py index c3706c3..de47ae4 100644 --- a/twscrape/models.py +++ b/twscrape/models.py @@ -189,25 +189,20 @@ class Tweet(JSONTrait): def parse(obj: dict, res: dict): tw_usr = User.parse(res["users"][obj["user_id_str"]]) - rt_id = _first( - obj, - [ - "retweeted_status_id_str", - "retweeted_status_result.result.rest_id", - "retweeted_status_result.result.tweet.rest_id" - ] - ) - rt_obj = get_or(res, f"tweets.{rt_id}") - - qt_id = _first( - obj, - [ - "quoted_status_id_str", - "quoted_status_result.result.rest_id" - "quoted_status_result.result.tweet.rest_id" - ] - ) - qt_obj = get_or(res, f"tweets.{qt_id}") + rt_id_path = [ + "retweeted_status_id_str", + "retweeted_status_result.result.rest_id", + "retweeted_status_result.result.tweet.rest_id", + ] + + qt_id_path = [ + "quoted_status_id_str", + "quoted_status_result.result.rest_id", + "quoted_status_result.result.tweet.rest_id", + ] + + rt_obj = get_or(res, f"tweets.{_first(obj, rt_id_path)}") + qt_obj = get_or(res, f"tweets.{_first(obj, qt_id_path)}") doc = Tweet( id=int(obj["id_str"]),