From 306df62a98181e0e0d61dd79683e020e6f9355e1 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Tue, 14 Jan 2025 17:50:44 +0100 Subject: [PATCH] Fix all instances of utcnow() --- src/auto_archiver/core/metadata.py | 2 +- src/auto_archiver/databases/gsheet_db.py | 2 +- src/auto_archiver/enrichers/meta_enricher.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auto_archiver/core/metadata.py b/src/auto_archiver/core/metadata.py index 8cd3f763..0a2ad076 100644 --- a/src/auto_archiver/core/metadata.py +++ b/src/auto_archiver/core/metadata.py @@ -21,7 +21,7 @@ class Metadata: media: List[Media] = field(default_factory=list) def __post_init__(self): - self.set("_processed_at", datetime.datetime.now(datetime.UTC)) + self.set("_processed_at", datetime.datetime.now(datetime.timezone.utc)) def merge(self: Metadata, right: Metadata, overwrite_left=True) -> Metadata: """ diff --git a/src/auto_archiver/databases/gsheet_db.py b/src/auto_archiver/databases/gsheet_db.py index ac8621df..98e72dcf 100644 --- a/src/auto_archiver/databases/gsheet_db.py +++ b/src/auto_archiver/databases/gsheet_db.py @@ -65,7 +65,7 @@ def batch_if_valid(col, val, final_value=None): media: Media = item.get_final_media() if hasattr(media, "urls"): batch_if_valid('archive', "\n".join(media.urls)) - batch_if_valid('date', True, datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()) + batch_if_valid('date', True, datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=datetime.timezone.utc).isoformat()) batch_if_valid('title', item.get_title()) batch_if_valid('text', item.get("content", "")) batch_if_valid('timestamp', item.get_timestamp()) diff --git a/src/auto_archiver/enrichers/meta_enricher.py b/src/auto_archiver/enrichers/meta_enricher.py index 0d84b9c4..b721bb54 100644 --- a/src/auto_archiver/enrichers/meta_enricher.py +++ b/src/auto_archiver/enrichers/meta_enricher.py @@ -55,5 +55,5 @@ def human_readable_bytes(self, size: int) -> str: def enrich_archive_duration(self, to_enrich): logger.debug(f"calculating archive duration for url={to_enrich.get_url()} ") - archive_duration = datetime.datetime.utcnow() - to_enrich.get("_processed_at") + archive_duration = datetime.datetime.now(datetime.timezone.utc) - to_enrich.get("_processed_at") to_enrich.set("archive_duration_seconds", archive_duration.seconds) \ No newline at end of file