Skip to content

Commit

Permalink
update readme on how to change search tab
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkens committed Nov 1, 2023
1 parent 6a232da commit d0fbef5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 14 additions & 19 deletions twscrape/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand Down

0 comments on commit d0fbef5

Please sign in to comment.