Skip to content

Commit e9bc4e7

Browse files
committed
feat(timeline): ✨ add api for get timeline by reverse chronalogical
ISSUES CLOSED: #115
1 parent 361dfc5 commit e9bc4e7

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

pytwitter/api.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,76 @@ def get_timelines(
718718
return_json=return_json,
719719
)
720720

721+
def get_timelines_reverse_chronological(
722+
self,
723+
user_id: str,
724+
*,
725+
start_time: Optional[str] = None,
726+
end_time: Optional[str] = None,
727+
since_id: Optional[str] = None,
728+
until_id: Optional[str] = None,
729+
max_results: Optional[int] = None,
730+
pagination_token: Optional[str] = None,
731+
exclude: Optional[Union[str, List, Tuple]] = None,
732+
tweet_fields: Optional[Union[str, List, Tuple]] = None,
733+
expansions: Optional[Union[str, List, Tuple]] = None,
734+
user_fields: Optional[Union[str, List, Tuple]] = None,
735+
media_fields: Optional[Union[str, List, Tuple]] = None,
736+
place_fields: Optional[Union[str, List, Tuple]] = None,
737+
poll_fields: Optional[Union[str, List, Tuple]] = None,
738+
return_json: bool = False,
739+
) -> Union[dict, md.Response]:
740+
"""
741+
Allows you to retrieve a collection of the most recent Tweets and Retweets posted by you and users you follow.
742+
This endpoint returns up to the last 3200 Tweets.
743+
744+
:param user_id: Unique identifier of the user that is requesting their chronological home timeline.
745+
:param start_time: Oldest or earliest UTC timestamp for tweets, format YYYY-MM-DDTHH:mm:ssZ.
746+
:param end_time: Newest or most recent UTC timestamp for tweets, format YYYY-MM-DDTHH:mm:ssZ.
747+
:param since_id: Greater than (that is, more recent than) tweet id for response. Exclude this since_id.
748+
:param until_id: Less than (that is, older than) tweet id for response. Exclude this until_id.
749+
:param max_results: The maximum number of results to be returned per page. Number between 5 and the 100.
750+
By default, each page will return 10 results.
751+
:param pagination_token: Token for the pagination.
752+
:param exclude: Fields for types of Tweets to exclude from the response.
753+
:param tweet_fields: Fields for the tweet object.
754+
:param expansions: Fields for the expansions.
755+
:param user_fields: Fields for the user object, Expansion required.
756+
:param media_fields: Fields for the media object, Expansion required.
757+
:param place_fields: Fields for the place object, Expansion required.
758+
:param poll_fields: Fields for the poll object, Expansion required.
759+
:param return_json: Type for returned data. If you set True JSON data will be returned.
760+
:return: Response instance or json.
761+
"""
762+
args = {
763+
"start_time": start_time,
764+
"end_time": end_time,
765+
"since_id": since_id,
766+
"until_id": until_id,
767+
"exclude": enf_comma_separated(name="exclude", value=exclude),
768+
"tweet.fields": enf_comma_separated(
769+
name="tweet_fields", value=tweet_fields
770+
),
771+
"expansions": enf_comma_separated(name="expansions", value=expansions),
772+
"user.fields": enf_comma_separated(name="user_fields", value=user_fields),
773+
"media.fields": enf_comma_separated(
774+
name="media_fields", value=media_fields
775+
),
776+
"place.fields": enf_comma_separated(
777+
name="place_fields", value=place_fields
778+
),
779+
"poll.fields": enf_comma_separated(name="poll_fields", value=poll_fields),
780+
"max_results": max_results,
781+
"pagination_token": pagination_token,
782+
}
783+
return self._get(
784+
url=f"{self.BASE_URL_V2}/users/{user_id}/timelines/reverse_chronological",
785+
params=args,
786+
cls=md.Tweet,
787+
multi=True,
788+
return_json=return_json,
789+
)
790+
721791
def get_mentions(
722792
self,
723793
user_id: str,

pytwitter/rate_limit.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def get_limit(self, auth_type, method="GET"):
6060
LIMIT_APP_GET=1500,
6161
LIMIT_USER_GET=900,
6262
)
63+
USER_TIMELINE_REVERSE = Endpoint(
64+
resource="/users/:id/timelines/reverse_chronological",
65+
regex=re.compile(r"/users/\d+/timelines/reverse_chronological"),
66+
LIMIT_USER_GET=180,
67+
)
6368
USER_MENTIONS = Endpoint(
6469
resource="/users/:id/mentions",
6570
regex=re.compile(r"/users/\d+/mentions"),
@@ -326,6 +331,7 @@ def get_limit(self, auth_type, method="GET"):
326331
TWEET_BY_ID,
327332
TWEETS_BY_ID,
328333
USER_TIMELINE,
334+
USER_TIMELINE_REVERSE,
329335
USER_MENTIONS,
330336
TWEET_SEARCH_RECENT,
331337
TWEET_SEARCH_ALL,

0 commit comments

Comments
 (0)