Skip to content

Commit

Permalink
Merge pull request #76 from stygmate/main
Browse files Browse the repository at this point in the history
Get RT and QT when they are in objects of type TweetWithVisibilityResults
  • Loading branch information
vladkens authored Nov 1, 2023
2 parents e0e7fb7 + 8eb9011 commit 100859c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions twscrape/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,24 @@ 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"])
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"])
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}")

doc = Tweet(
Expand Down Expand Up @@ -230,12 +244,8 @@ def parse(obj: dict, res: dict):
# issue #42 – restore full rt text
rt = doc.retweetedTweet
if rt is not None and rt.user is not None and doc.rawContent.endswith("…"):
# prefix = f"RT @{rt.user.username}: "
# if login changed, old login can be cached in rawContent, so use less strict check
prefix = "RT @"

rt_msg = f"{prefix}{rt.rawContent}"
if doc.rawContent != rt_msg and doc.rawContent.startswith(prefix):
rt_msg = f"RT @{rt.user.username}: {rt.rawContent}"
if doc.rawContent != rt_msg:
doc.rawContent = rt_msg

return doc
Expand Down

0 comments on commit 100859c

Please sign in to comment.