diff options
author | halcy <halcy@ARARAGI-KUN> | 2022-11-24 22:56:49 +0200 |
---|---|---|
committer | halcy <halcy@ARARAGI-KUN> | 2022-11-24 22:56:49 +0200 |
commit | 00a96c5e9584bcd768d51372fbc4ccd866432771 (patch) | |
tree | f979bcc269b3f4a65d6bc56bfff14a3f91f39866 /mastodon | |
parent | c3cfb197a6afaf441d452fa57cb1bbee211ca4b4 (diff) | |
download | mastodon.py-00a96c5e9584bcd768d51372fbc4ccd866432771.tar.gz |
Add trending APIs
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index bb2d9d8..a4fe768 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -264,7 +264,7 @@ class Mastodon: | |||
264 | Create a new app with given `client_name` and `scopes` (The basic scopes are "read", "write", "follow" and "push" | 264 | Create a new app with given `client_name` and `scopes` (The basic scopes are "read", "write", "follow" and "push" |
265 | - more granular scopes are available, please refer to Mastodon documentation for which) on the instance given | 265 | - more granular scopes are available, please refer to Mastodon documentation for which) on the instance given |
266 | by `api_base_url`. | 266 | by `api_base_url`. |
267 | 267 | ||
268 | Specify `redirect_uris` if you want users to be redirected to a certain page after authenticating in an OAuth flow. | 268 | Specify `redirect_uris` if you want users to be redirected to a certain page after authenticating in an OAuth flow. |
269 | You can specify multiple URLs by passing a list. Note that if you wish to use OAuth authentication with redirects, | 269 | You can specify multiple URLs by passing a list. Note that if you wish to use OAuth authentication with redirects, |
270 | the redirect URI must be one of the URLs specified here. | 270 | the redirect URI must be one of the URLs specified here. |
@@ -1535,9 +1535,16 @@ class Mastodon: | |||
1535 | ### | 1535 | ### |
1536 | # Reading data: Trends | 1536 | # Reading data: Trends |
1537 | ### | 1537 | ### |
1538 | @api_version("2.4.3", "3.0.0", __DICT_VERSION_HASHTAG) | 1538 | @api_version("2.4.3", "3.5.0", __DICT_VERSION_HASHTAG) |
1539 | def trends(self, limit=None): | 1539 | def trends(self, limit=None): |
1540 | """ | 1540 | """ |
1541 | Alias for `trending_tags()`_ | ||
1542 | """ | ||
1543 | return self.trending_tags(limit = limit) | ||
1544 | |||
1545 | @api_version("3.5.0", "3.5.0", __DICT_VERSION_HASHTAG) | ||
1546 | def trending_tags(self, limit=None): | ||
1547 | """ | ||
1541 | Fetch trending-hashtag information, if the instance provides such information. | 1548 | Fetch trending-hashtag information, if the instance provides such information. |
1542 | 1549 | ||
1543 | Specify `limit` to limit how many results are returned (the maximum number | 1550 | Specify `limit` to limit how many results are returned (the maximum number |
@@ -1546,13 +1553,45 @@ class Mastodon: | |||
1546 | Does not require authentication unless locked down by the administrator. | 1553 | Does not require authentication unless locked down by the administrator. |
1547 | 1554 | ||
1548 | Important versioning note: This endpoint does not exist for Mastodon versions | 1555 | Important versioning note: This endpoint does not exist for Mastodon versions |
1549 | between 2.8.0 (inclusive) and 3.0.0 (exclusive). | 1556 | between 2.8.0 (inclusive) and 3.0.0 (exclusive). |
1550 | 1557 | ||
1551 | Returns a list of `hashtag dicts`_, sorted by the instance's trending algorithm, | 1558 | Returns a list of `hashtag dicts`_, sorted by the instance's trending algorithm, |
1552 | descending. | 1559 | descending. |
1553 | """ | 1560 | """ |
1554 | params = self.__generate_params(locals()) | 1561 | params = self.__generate_params(locals()) |
1555 | return self.__api_request('GET', '/api/v1/trends', params) | 1562 | if self.verify_minimum_version("3.5.0", cached=True): |
1563 | # Starting 3.5.0, old version is deprecated | ||
1564 | return self.__api_request('GET', '/api/v1/trends/tags', params) | ||
1565 | else: | ||
1566 | return self.__api_request('GET', '/api/v1/trends', params) | ||
1567 | |||
1568 | @api_version("3.5.0", "3.5.0", __DICT_VERSION_STATUS) | ||
1569 | def trending_statuses(self): | ||
1570 | """ | ||
1571 | Fetch trending-status information, if the instance provides such information. | ||
1572 | |||
1573 | Specify `limit` to limit how many results are returned (the maximum number | ||
1574 | of results is 10, the endpoint is not paginated). | ||
1575 | |||
1576 | Returns a list of `status dicts`_, sorted by the instances's trending algorithm, | ||
1577 | descending. | ||
1578 | """ | ||
1579 | params = self.__generate_params(locals()) | ||
1580 | return self.__api_request('GET', '/api/v1/trends/statuses', params) | ||
1581 | |||
1582 | @api_version("3.5.0", "3.5.0", __DICT_VERSION_CARD) | ||
1583 | def trending_links(self): | ||
1584 | """ | ||
1585 | Fetch trending-link information, if the instance provides such information. | ||
1586 | |||
1587 | Specify `limit` to limit how many results are returned (the maximum number | ||
1588 | of results is 10, the endpoint is not paginated). | ||
1589 | |||
1590 | Returns a list of `card dicts`_, sorted by the instances's trending algorithm, | ||
1591 | descending. | ||
1592 | """ | ||
1593 | params = self.__generate_params(locals()) | ||
1594 | return self.__api_request('GET', '/api/v1/trends/links', params) | ||
1556 | 1595 | ||
1557 | ### | 1596 | ### |
1558 | # Reading data: Lists | 1597 | # Reading data: Lists |