Skip to content

Commit

Permalink
Implement update method
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Jul 8, 2024
1 parent b20b415 commit 6766dd7
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions plextraktsync/db/SyncDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ def insert(self, record: SyncRecord):
pass

def update(self, m: Media):
record = SyncRecord(
media_id=m.trakt_id,
plex_timestamp_watched=m.watched_on_plex,
seen_on_plex_sync=m.watched_on_plex,
trakt_timestamp_watched=m.watched_on_trakt,
seen_on_trakt_sync=m.watched_on_trakt,
result="",
)
print(record)
record = self.find_by_id(m.type, m.trakt_id)
if record:
record.plex_timestamp_watched = m.watched_on_plex
record.seen_on_plex_sync = m.watched_on_plex
record.trakt_timestamp_watched = m.watched_on_trakt
record.seen_on_trakt_sync = m.watched_on_trakt
else:
record = SyncRecord(
media_type=m.type,
trakt_id=m.trakt_id,
plex_timestamp_watched=m.watched_on_plex,
seen_on_plex_sync=m.watched_on_plex,
trakt_timestamp_watched=m.watched_on_trakt,
seen_on_trakt_sync=m.watched_on_trakt,
)
with Session(self.engine) as session:
session.add(record)
session.commit()

0 comments on commit 6766dd7

Please sign in to comment.