[twitter] fix crash when using 'expand' and 'syndication'
caused by KeyError: 'conversation_id_str'
This commit is contained in:
@@ -2635,6 +2635,8 @@ Description
|
|||||||
for each Tweet in said timeline.
|
for each Tweet in said timeline.
|
||||||
|
|
||||||
Note: This requires at least 1 additional API call per initial Tweet.
|
Note: This requires at least 1 additional API call per initial Tweet.
|
||||||
|
Age-restricted Tweets cannot be expanded when using the
|
||||||
|
`syndication <extractor.twitter.syndication_>`__ API.
|
||||||
|
|
||||||
|
|
||||||
extractor.twitter.size
|
extractor.twitter.size
|
||||||
|
|||||||
@@ -361,18 +361,22 @@ class TwitterExtractor(Extractor):
|
|||||||
def _expand_tweets(self, tweets):
|
def _expand_tweets(self, tweets):
|
||||||
seen = set()
|
seen = set()
|
||||||
for tweet in tweets:
|
for tweet in tweets:
|
||||||
|
obj = tweet["legacy"] if "legacy" in tweet else tweet
|
||||||
if "legacy" in tweet:
|
cid = obj.get("conversation_id_str")
|
||||||
cid = tweet["legacy"]["conversation_id_str"]
|
if not cid:
|
||||||
else:
|
tid = obj["id_str"]
|
||||||
cid = tweet["conversation_id_str"]
|
self.log.warning(
|
||||||
|
"Unable to expand %s (no 'conversation_id')", tid)
|
||||||
if cid not in seen:
|
continue
|
||||||
seen.add(cid)
|
if cid in seen:
|
||||||
try:
|
self.log.debug(
|
||||||
yield from self.api.tweet_detail(cid)
|
"Skipping expansion of %s (previously seen)", cid)
|
||||||
except Exception:
|
continue
|
||||||
yield tweet
|
seen.add(cid)
|
||||||
|
try:
|
||||||
|
yield from self.api.tweet_detail(cid)
|
||||||
|
except Exception:
|
||||||
|
yield tweet
|
||||||
|
|
||||||
def _make_tweet(self, user, id_str, url, timestamp):
|
def _make_tweet(self, user, id_str, url, timestamp):
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user