-
Notifications
You must be signed in to change notification settings - Fork 5
[Feature] added get_history function #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -528,6 +528,54 @@ def get_collection(list_type=None, extended=None): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| results.append(TVShow(**d.pop('show'))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yield results | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_history(list_type=None, id=None, start_at=None, end_at=None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Returns movies and episodes that a user has watched, sorted by most recent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param list_type: Optional Filter by a specific type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Possible values: movies or episodes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param id: Optional Trakt ID for a specific item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param start_at : Optional, A `datetime.datetime` object or `str`, Filter by watched date starting at. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param end_at : Optional, A `datetime.datetime` object or `str`, Filter by watched date ending at. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| valid_type = ('movies', 'episodes') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if list_type and list_type not in valid_type: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError('list_type must be one of {}'.format(valid_type)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uri = 'sync/history' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if list_type: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uri += '/{}'.format(list_type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if id: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uri += '/{}'.format(id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not isinstance(start_at, str): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| start_at = timestamp(start_at) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if start_at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uri += '?start_at={start_at}'.format(start_at=start_at) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not isinstance(end_at, str): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end_at = timestamp(end_at) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if end_at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uri += '?end_at={end_at}'.format(end_at=end_at) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = yield uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| results = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for d in data: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if 'movie' in d: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from trakt.movies import Movie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| results.append(Movie(**d.pop('movie'))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif 'show' in d: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from trakt.tv import TVShow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| results.append(TVShow(**d.pop('show'))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yield results | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+567
to
+577
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return TVEpisode for episode history entries (currently returns TVShow) History responses include an Apply this diff: results = []
for d in data:
if 'movie' in d:
from trakt.movies import Movie
results.append(Movie(**d.pop('movie')))
- elif 'show' in d:
- from trakt.tv import TVShow
-
- results.append(TVShow(**d.pop('show')))
+ elif 'episode' in d:
+ from trakt.tv import TVEpisode
+ show = d.pop('show', {}) # expected for episodes
+ episode = d.pop('episode')
+ results.append(TVEpisode(
+ show.get('title', None),
+ show_id=(show.get('ids') or {}).get('trakt'),
+ **episode
+ ))
+ elif 'show' in d:
+ from trakt.tv import TVShow
+ results.append(TVShow(**d.pop('show')))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @post | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix None handling and join query params correctly for start_at/end_at
timestamp(None)will raise, and using?twice yields an invalid URL when both params are present.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents