feat: view explore page trends and search for posts in a trend #234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for X's Explore Page trending content
This PR adds the ability to fetch trending keywords and hashtags from X's Explore page by querying X's GenericTimelineById endpoint.
Changes
twscrape.api
"querySource": "trend_click"
totwscrape.api.search_raw
twscrape.utils
def to_old_rep(obj: dict) -> dict[str, dict]
so that it can now parse TimelineTrend items; returns{"tweets": {**tw1, **tw2}, "users": users, "trends": trends}
twscrape.models
list_explore_raw
and returns a Generator of TimelineTrend objectsmodified
parse_items
so it can now handle a response with TimelineTrend objectscreated a new dataclass
class TimelineTrend(JSONTrait)
Example Usage
Notes
list_explore
requires a timeline_id as GenericTimelineById allows searching for 4 different timelines categories: trending, news, sports and entertainment. Their various IDs are currently only listed in thetimeline_to_id
dictionary in thelist_trending
method. I think some mapper from timeline category to ID could be added to thelist_explore
method which could then take one of the 4 categories as a parameter. However, this seemed different from how the other methods operated so I decided not to impose this.I can add this in a modification to this PR if needed !