-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from MerleLiuKun/feat-trends
Feat trends
- Loading branch information
Showing
10 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ env.bak/ | |
venv.bak/ | ||
|
||
# mkdocs documentation | ||
/site | ||
docs/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
The Trends lookup endpoint allow developers to get the Trends for a location, specified using the where-on-earth id (WOEID). | ||
|
||
**Note:** WOEID is a legacy identifier created by Yahoo and has been deprecated. X API uses the numeric value to identify town and country trend locations. | ||
Reference our legacy [blog post](https://blog.twitter.com/engineering/en_us/a/2010/woeids-in-twitters-trends.html), or [archived data](https://archive.org/details/geoplanet_data_7.10.0.zip0.) | ||
|
||
### Get trends | ||
|
||
Get the trends for a location | ||
|
||
```python | ||
api.get_trends_by_woeid(woeid=1) | ||
# Response(data=[Trend(trend_name='#QuietOnSet', tweet_count=14060), Trend(trend_name='King Charles', tweet_count=42315), Trend(trend_name='Drake Bell', tweet_count=1234)]) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Trend Object | ||
Refer: https://developer.twitter.com/en/docs/twitter-api/trends/api-reference/get-trends-by-woeid | ||
""" | ||
|
||
from dataclasses import dataclass, field | ||
|
||
from .base import BaseModel | ||
|
||
|
||
@dataclass | ||
class Trend(BaseModel): | ||
""" | ||
A class representing Trend object | ||
""" | ||
|
||
trend_name: str = field(default=None) | ||
tweet_count: int = field(default=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":[{"trend_name":"#TEZOSTUESDAY","tweet_count":14869},{"trend_name":"Copenhagen","tweet_count":13005},{"trend_name":"Roses","tweet_count":32193},{"trend_name":"Heroes","tweet_count":69798},{"trend_name":"Cedric","tweet_count":14259},{"trend_name":"#AskSonic","tweet_count":8908},{"trend_name":"Nelson","tweet_count":29841},{"trend_name":"#PSVARS","tweet_count":4915},{"trend_name":"Eddie","tweet_count":34139},{"trend_name":"Saliba","tweet_count":7191},{"trend_name":"Walters","tweet_count":8095},{"trend_name":"Bakayoko","tweet_count":1809},{"trend_name":"Bibby Stockholm","tweet_count":21021},{"trend_name":"Nwaneri","tweet_count":5783},{"trend_name":"Doncaster","tweet_count":3551},{"trend_name":"Kiwior","tweet_count":1535}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
tests for the trends api | ||
""" | ||
|
||
import responses | ||
|
||
|
||
@responses.activate | ||
def test_get_trends_by_woeid(api, helpers): | ||
responses.add( | ||
responses.GET, | ||
url="https://api.twitter.com/2/trends/by/woeid/1", | ||
json=helpers.load_json_data("testdata/apis/trends/trends_resp.json"), | ||
) | ||
|
||
resp = api.get_trends_by_woeid(1) | ||
assert resp.data[0].trend_name == "#TEZOSTUESDAY" |