[format] Blacken some files
This commit is contained in:
@ -146,7 +146,9 @@ def build_book_map(rows) -> dict:
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
book = Book.objects.filter(
|
book = Book.objects.filter(
|
||||||
koreader_data_by_hash__icontains=book_row[KoReaderBookColumn.MD5.value]
|
koreader_data_by_hash__icontains=book_row[
|
||||||
|
KoReaderBookColumn.MD5.value
|
||||||
|
]
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if not book:
|
if not book:
|
||||||
@ -200,11 +202,15 @@ def build_page_data(page_rows: list, book_map: dict, user_tz=None) -> dict:
|
|||||||
"end_ts": start_ts + duration,
|
"end_ts": start_ts + duration,
|
||||||
}
|
}
|
||||||
if book_ids_not_found:
|
if book_ids_not_found:
|
||||||
logger.info(f"Found pages for books not in file: {set(book_ids_not_found)}")
|
logger.info(
|
||||||
|
f"Found pages for books not in file: {set(book_ids_not_found)}"
|
||||||
|
)
|
||||||
return book_map
|
return book_map
|
||||||
|
|
||||||
|
|
||||||
def build_scrobbles_from_book_map(book_map: dict, user: "User") -> list["Scrobble"]:
|
def build_scrobbles_from_book_map(
|
||||||
|
book_map: dict, user: "User"
|
||||||
|
) -> list["Scrobble"]:
|
||||||
Scrobble = apps.get_model("scrobbles", "Scrobble")
|
Scrobble = apps.get_model("scrobbles", "Scrobble")
|
||||||
|
|
||||||
scrobbles_to_create = []
|
scrobbles_to_create = []
|
||||||
@ -234,9 +240,9 @@ def build_scrobbles_from_book_map(book_map: dict, user: "User") -> list["Scrobbl
|
|||||||
|
|
||||||
seconds_from_last_page = 0
|
seconds_from_last_page = 0
|
||||||
if prev_page_stats:
|
if prev_page_stats:
|
||||||
seconds_from_last_page = stats.get("end_ts") - prev_page_stats.get(
|
seconds_from_last_page = stats.get(
|
||||||
"start_ts"
|
"end_ts"
|
||||||
)
|
) - prev_page_stats.get("start_ts")
|
||||||
|
|
||||||
playback_position_seconds = playback_position_seconds + stats.get(
|
playback_position_seconds = playback_position_seconds + stats.get(
|
||||||
"duration"
|
"duration"
|
||||||
@ -245,7 +251,9 @@ def build_scrobbles_from_book_map(book_map: dict, user: "User") -> list["Scrobbl
|
|||||||
end_of_reading = pages_processed == total_pages_read
|
end_of_reading = pages_processed == total_pages_read
|
||||||
big_jump_to_this_page = (cur_page_number - last_page_number) > 10
|
big_jump_to_this_page = (cur_page_number - last_page_number) > 10
|
||||||
is_session_gap = seconds_from_last_page > SESSION_GAP_SECONDS
|
is_session_gap = seconds_from_last_page > SESSION_GAP_SECONDS
|
||||||
if (is_session_gap and not big_jump_to_this_page) or end_of_reading:
|
if (
|
||||||
|
is_session_gap and not big_jump_to_this_page
|
||||||
|
) or end_of_reading:
|
||||||
should_create_scrobble = True
|
should_create_scrobble = True
|
||||||
|
|
||||||
if should_create_scrobble:
|
if should_create_scrobble:
|
||||||
@ -373,7 +381,9 @@ def process_koreader_sqlite_file(file_path, user_id) -> list:
|
|||||||
return new_scrobbles
|
return new_scrobbles
|
||||||
|
|
||||||
book_map = build_page_data(
|
book_map = build_page_data(
|
||||||
cur.execute("SELECT * from page_stat_data ORDER BY id_book, start_time"),
|
cur.execute(
|
||||||
|
"SELECT * from page_stat_data ORDER BY id_book, start_time"
|
||||||
|
),
|
||||||
book_map,
|
book_map,
|
||||||
tz,
|
tz,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -237,9 +237,7 @@ REST_FRAMEWORK = {
|
|||||||
"rest_framework.authentication.SessionAuthentication",
|
"rest_framework.authentication.SessionAuthentication",
|
||||||
],
|
],
|
||||||
"DEFAULT_CONTENT_NEGOTIATION_CLASS": "vrobbler.negotiation.IgnoreClientContentNegotiation",
|
"DEFAULT_CONTENT_NEGOTIATION_CLASS": "vrobbler.negotiation.IgnoreClientContentNegotiation",
|
||||||
"DEFAULT_FILTER_BACKENDS": [
|
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
|
||||||
"django_filters.rest_framework.DjangoFilterBackend"
|
|
||||||
],
|
|
||||||
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
|
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
|
||||||
"PAGE_SIZE": 200,
|
"PAGE_SIZE": 200,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user