forked from crocodilestick/Calibre-Web-Automated
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkobo_sync_utils.py
More file actions
36 lines (27 loc) · 1.08 KB
/
kobo_sync_utils.py
File metadata and controls
36 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Calibre-Web Automated – fork of Calibre-Web
# Copyright (C) 2018-2026 Calibre-Web contributors
# Copyright (C) 2024-2026 Calibre-Web Automated contributors
# SPDX-License-Identifier: GPL-3.0-or-later
# See CONTRIBUTORS for full list of authors.
"""Helpers for Kobo sync logic."""
from datetime import datetime
import logging
log = logging.getLogger(__name__)
def get_kobo_created_ts(book):
ts_created = None
if book.Books.timestamp is not None:
ts_created = book.Books.timestamp.replace(tzinfo=None)
else:
log.debug("Kobo Sync: book %s has no timestamp", book.Books.id)
try:
if book.date_added is not None:
ts_created = max(ts_created, book.date_added) if ts_created else book.date_added
else:
log.debug("Kobo Sync: book %s has no date_added", book.Books.id)
except AttributeError:
pass
if ts_created is None and book.Books.last_modified is not None:
ts_created = book.Books.last_modified.replace(tzinfo=None)
if ts_created is None:
ts_created = datetime.min
return ts_created