[twitter] add 'search-results' option (#8613)
This commit is contained in:
@@ -6333,6 +6333,20 @@ Description
|
|||||||
to the Tweet ID value of the last retrieved Tweet.
|
to the Tweet ID value of the last retrieved Tweet.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.twitter.search-results
|
||||||
|
--------------------------------
|
||||||
|
Type
|
||||||
|
``string``
|
||||||
|
Default
|
||||||
|
``"latest"``
|
||||||
|
Description
|
||||||
|
Determines the target of search results.
|
||||||
|
Supported Values
|
||||||
|
* ``"top"``
|
||||||
|
* ``"media"``
|
||||||
|
* ``"latest"`` | ``"live"``
|
||||||
|
|
||||||
|
|
||||||
extractor.twitter.search-stop
|
extractor.twitter.search-stop
|
||||||
-----------------------------
|
-----------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -880,6 +880,7 @@
|
|||||||
"retweets" : false,
|
"retweets" : false,
|
||||||
"search-limit": 20,
|
"search-limit": 20,
|
||||||
"search-pagination": "cursor",
|
"search-pagination": "cursor",
|
||||||
|
"search-results" : "latest",
|
||||||
"search-stop" : "auto",
|
"search-stop" : "auto",
|
||||||
"size" : ["orig", "4096x4096", "large", "medium", "small"],
|
"size" : ["orig", "4096x4096", "large", "medium", "small"],
|
||||||
"text-tweets" : false,
|
"text-tweets" : false,
|
||||||
|
|||||||
@@ -1450,23 +1450,36 @@ class TwitterAPI():
|
|||||||
endpoint, variables, ("bookmark_timeline_v2", "timeline"),
|
endpoint, variables, ("bookmark_timeline_v2", "timeline"),
|
||||||
stop_tweets=128)
|
stop_tweets=128)
|
||||||
|
|
||||||
def search_timeline(self, query, product="Latest"):
|
def search_timeline(self, query, product=None):
|
||||||
|
cfg = self.extractor.config
|
||||||
|
|
||||||
|
if product is None:
|
||||||
|
if product := cfg("search-results"):
|
||||||
|
product = {
|
||||||
|
"top" : "Top",
|
||||||
|
"live" : "Latest",
|
||||||
|
"user" : "People",
|
||||||
|
"media": "Media",
|
||||||
|
"list" : "Lists",
|
||||||
|
}.get(product.lower(), product).capitalize()
|
||||||
|
else:
|
||||||
|
product = "Latest"
|
||||||
|
|
||||||
endpoint = "/graphql/4fpceYZ6-YQCx_JSl_Cn_A/SearchTimeline"
|
endpoint = "/graphql/4fpceYZ6-YQCx_JSl_Cn_A/SearchTimeline"
|
||||||
variables = {
|
variables = {
|
||||||
"rawQuery": query,
|
"rawQuery": query,
|
||||||
"count": self.extractor.config("search-limit", 20),
|
"count": cfg("search-limit", 20),
|
||||||
"querySource": "typed_query",
|
"querySource": "typed_query",
|
||||||
"product": product,
|
"product": product,
|
||||||
"withGrokTranslatedBio": False,
|
"withGrokTranslatedBio": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.extractor.config("search-pagination") in (
|
if cfg("search-pagination") in ("max_id", "maxid", "id"):
|
||||||
"max_id", "maxid", "id"):
|
|
||||||
update_variables = self._update_variables_search
|
update_variables = self._update_variables_search
|
||||||
else:
|
else:
|
||||||
update_variables = None
|
update_variables = None
|
||||||
|
|
||||||
stop_tweets = self.extractor.config("search-stop")
|
stop_tweets = cfg("search-stop")
|
||||||
if stop_tweets is None or stop_tweets == "auto":
|
if stop_tweets is None or stop_tweets == "auto":
|
||||||
stop_tweets = 3 if update_variables is None else 0
|
stop_tweets = 3 if update_variables is None else 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user