From ea7c6786c2f4e4cd1e757d0d10e7127044158406 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Tue, 28 Feb 2023 20:16:07 +0000 Subject: [PATCH] Handle TweetWithVisibilityResults on quoted tweets Fixes #604 --- snscrape/modules/twitter.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/snscrape/modules/twitter.py b/snscrape/modules/twitter.py index 8cf0791..d59fc34 100644 --- a/snscrape/modules/twitter.py +++ b/snscrape/modules/twitter.py @@ -1416,9 +1416,12 @@ class _TwitterAPIScraper(snscrape.base.Scraper): if result['quotedRefResult']['result']['__typename'] == 'TweetTombstone': kwargs['quotedTweet'] = self._graphql_timeline_tweet_item_result_to_tweet(result['quotedRefResult']['result'], tweetId = int(tweet['quoted_status_id_str'])) else: - if result['quotedRefResult']['result']['__typename'] != 'Tweet': + qTweet = result['quotedRefResult']['result'] + if result['quotedRefResult']['result']['__typename'] not in ('Tweet', 'TweetWithVisibilityResults'): _logger.warning(f'Unknown quotedRefResult type {result["quotedRefResult"]["result"]["__typename"]!r} on tweet {self._get_tweet_id(tweet)}, using TweetRef') - kwargs['quotedTweet'] = TweetRef(id = int(result['quotedRefResult']['result']['rest_id'])) + elif result['quotedRefResult']['result']['__typename'] == 'TweetWithVisibilityResults': + qTweet = qTweet['tweet'] + kwargs['quotedTweet'] = TweetRef(id = int(qTweet['rest_id'])) elif 'quoted_status_id_str' in tweet: # Omit the TweetRef if this is a retweet and the quoted tweet ID matches the tweet quoted in the retweeted tweet. if tweet['quoted_status_id_str'] != tweet.get('retweeted_status_result', {}).get('result', {}).get('quoted_status_result', {}).get('result', {}).get('rest_id'):