-
Notifications
You must be signed in to change notification settings - Fork 6
[Feature] added get_history function #2 #92
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 'episode' in d: | ||||||||||||||||||||||||||||||||
| from trakt.tv import TVEpisode | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| results.append(TVEpisode(**d.pop('episode'))) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
Comment on lines
+572
to
+576
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. Bug: TVEpisode constructed without required show context TVEpisode requires show context; constructing with only episode dict will raise or produce an invalid object. Follow the existing pattern used elsewhere in this module. Apply this diff: - elif 'episode' in d:
- from trakt.tv import TVEpisode
-
- results.append(TVEpisode(**d.pop('episode')))
+ elif 'episode' in d:
+ from trakt.tv import TVEpisode
+ show = d.pop('show')
+ ep = d.pop('episode')
+ results.append(
+ TVEpisode(
+ show.get('title', None),
+ show_id=show['ids'].get('trakt'),
+ **ep
+ )
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| yield results | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @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.
Bug: None handling and malformed query string for start_at/end_at
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents