[twitter] simplify 'expand' & 'unique' init code

This commit is contained in:
Mike Fährmann
2025-06-05 15:33:08 +02:00
parent 72a01bc4d4
commit 8dace96af3

View File

@@ -13,7 +13,6 @@ from .. import text, util, exception
from ..cache import cache, memcache
import itertools
import random
import re
BASE_PATTERN = (r"(?:https?://)?(?:www\.|mobile\.)?"
r"(?:(?:[fv]x)?twitter|(?:fix(?:up|v))?x)\.com")
@@ -72,21 +71,16 @@ class TwitterExtractor(Extractor):
self.login()
self.api = TwitterAPI(self)
metadata = self.metadata()
if self.config("expand"):
tweets = self._expand_tweets(self.tweets())
self.tweets = lambda : tweets
if self.config("unique", True):
seen_tweets = set()
else:
seen_tweets = None
seen_tweets = set() if self.config("unique", True) else None
if self.twitpic:
self._find_twitpic = re.compile(
self._find_twitpic = util.re(
r"https?(://twitpic\.com/(?!photos/)\w+)").findall
for tweet in self.tweets():
tweets = self.tweets()
if self.config("expand"):
tweets = self._expand_tweets(tweets)
for tweet in tweets:
if "legacy" in tweet:
data = tweet["legacy"]