Skip to content

Commit

Permalink
Feature: Allow rate rated_at to be str or datetime (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc authored Feb 21, 2024
2 parents 4879a35 + af7995c commit 23f2bb5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions trakt/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ def rate(media, rating, rated_at=None):
:param media: The media object to post a rating to
:param rating: A rating from 1 to 10 for the media item
:param rated_at: A `datetime.datetime` object indicating the time at which
:param rated_at: A `datetime.datetime` object or `str` indicating the time at which
this rating was created
"""
if rated_at is None:
rated_at = datetime.now(tz=timezone.utc)
if not isinstance(rated_at, str):
rated_at = timestamp(rated_at)

data = dict(rating=rating, rated_at=timestamp(rated_at))
data = dict(rating=rating, rated_at=rated_at)
data.update(media.ids)
result = yield 'sync/ratings', {media.media_type: [data]}
yield result
Expand Down

0 comments on commit 23f2bb5

Please sign in to comment.