From cf6a9fb1f4b2d9b11114e1ec79056985de4db87d Mon Sep 17 00:00:00 2001 From: Craig Alexander Date: Thu, 4 Sep 2025 01:24:46 -0400 Subject: [PATCH] Fix precommit checks --- backend/download/src/queue.py | 18 ++++++++++++------ .../tests/test_src/test_pending_list.py | 5 ++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/download/src/queue.py b/backend/download/src/queue.py index cd355cad..bc97b0b1 100644 --- a/backend/download/src/queue.py +++ b/backend/download/src/queue.py @@ -6,12 +6,13 @@ Functionality: import json from datetime import datetime +from zoneinfo import ZoneInfo from appsettings.src.config import AppConfig from channel.src.index import YoutubeChannel from channel.src.remote_query import get_last_channel_videos -from common.src.es_connect import ElasticWrap, IndexPaginate from common.src.env_settings import EnvironmentSettings +from common.src.es_connect import ElasticWrap, IndexPaginate from common.src.helper import ( get_channels, get_duration_str, @@ -24,7 +25,6 @@ from download.src.thumbnails import ThumbManager from playlist.src.index import YoutubePlaylist from video.src.constants import VideoTypeEnum from video.src.index import YoutubeVideo -from zoneinfo import ZoneInfo class PendingIndex: @@ -402,9 +402,13 @@ class PendingList(PendingIndex): upload_date = video_data.get("upload_date") if upload_date: upload_date_time = datetime.strptime(upload_date, "%Y%m%d") - return upload_date_time.replace(tzinfo=ZoneInfo(EnvironmentSettings.TZ)).timestamp() + return upload_date_time.replace( + tzinfo=ZoneInfo(EnvironmentSettings.TZ) + ).timestamp() - return int(datetime.now(tz=ZoneInfo(EnvironmentSettings.TZ)).timestamp()) + return int( + datetime.now(tz=ZoneInfo(EnvironmentSettings.TZ)).timestamp() + ) def __extract_vid_type(self, video_data) -> str: """build vid type""" @@ -457,7 +461,9 @@ class PendingList(PendingIndex): # add last newline bulk_list.append("\n") query_str = "\n".join(bulk_list) - response, status_code = ElasticWrap("_bulk").post(query_str, ndjson=True) + response, status_code = ElasticWrap("_bulk").post( + query_str, ndjson=True + ) print(response) if status_code != 200: self._notify_fail(status_code) @@ -538,7 +544,7 @@ class PendingList(PendingIndex): """failed to add""" if not self.task: return - + message_lines = [ "Adding extracted videos failed.", f"Status code: {status_code}", diff --git a/backend/download/tests/test_src/test_pending_list.py b/backend/download/tests/test_src/test_pending_list.py index 4502d5d5..24f15ebd 100644 --- a/backend/download/tests/test_src/test_pending_list.py +++ b/backend/download/tests/test_src/test_pending_list.py @@ -1,6 +1,7 @@ """tests for PendingList functions""" from datetime import datetime, timezone + from download.src.queue import PendingList @@ -9,6 +10,7 @@ def test_returns_timestamp_if_present(): result = PendingList._PendingList__extract_published(video_data) assert result == 1508457600 + def test_returns_iso_date_if_upload_date_present(): video_data = {"upload_date": "20171020"} result = PendingList._PendingList__extract_published(video_data) @@ -21,6 +23,7 @@ def test_returns_iso_date_if_upload_date_present(): assert dt.minute == 0 assert dt.second == 0 + def test_returns_current_timestamp_if_no_date_info(): video_data = {} @@ -28,4 +31,4 @@ def test_returns_current_timestamp_if_no_date_info(): result = PendingList._PendingList__extract_published(video_data) after = int(datetime.now().timestamp()) - assert before <= result <= after \ No newline at end of file + assert before <= result <= after