From e057475ec43097d11be5e8d050412b69e45a2cd9 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Mon, 12 Aug 2024 13:43:01 +0100 Subject: [PATCH] chore: timezone.utc -> UTC --- x_notes/health_check.py | 4 ++-- x_notes/helpers.py | 4 ++-- x_notes/meta.py | 6 +++--- x_notes/notes.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x_notes/health_check.py b/x_notes/health_check.py index 02031c4b..c0a44c6c 100644 --- a/x_notes/health_check.py +++ b/x_notes/health_check.py @@ -1,5 +1,5 @@ import json -from datetime import datetime, timedelta, timezone +from datetime import UTC, datetime, timedelta from io import BytesIO import requests @@ -12,7 +12,7 @@ def health_check() -> None: "https://github.com/andylolz/x-community-notes/raw/gh-pages/_data/meta.json" ) meta = json.load(BytesIO(r.content)) - delta = datetime.now(timezone.utc) - datetime.fromisoformat(meta["most_recent"]) + delta = datetime.now(UTC) - datetime.fromisoformat(meta["most_recent"]) if delta > timedelta(days=MAX_AGE_IN_DAYS): raise Exception(f"Most recent tweet is more than {MAX_AGE_IN_DAYS} days old.") diff --git a/x_notes/helpers.py b/x_notes/helpers.py index d9cc5446..73dd5acf 100644 --- a/x_notes/helpers.py +++ b/x_notes/helpers.py @@ -1,13 +1,13 @@ import json from collections import defaultdict -from datetime import datetime, timezone +from datetime import UTC, datetime from typing import Any from loguru import logger def to_isoformat(ms_since_epoch: str) -> str: - return datetime.fromtimestamp(int(ms_since_epoch[:-3]), timezone.utc).isoformat() + return datetime.fromtimestamp(int(ms_since_epoch[:-3]), UTC).isoformat() def load_notes(filepath: str = "output/data/notes.json") -> dict[str, dict[str, Any]]: diff --git a/x_notes/meta.py b/x_notes/meta.py index b35810ac..ae3f8927 100644 --- a/x_notes/meta.py +++ b/x_notes/meta.py @@ -1,5 +1,5 @@ import json -from datetime import datetime, timezone +from datetime import UTC, datetime from typing import Any @@ -12,7 +12,7 @@ def account_locked_until() -> str | None: meta = load_meta() if not meta.get("locked_until"): return None - if datetime.fromisoformat(meta["locked_until"]) < datetime.now(timezone.utc): + if datetime.fromisoformat(meta["locked_until"]) < datetime.now(UTC): return None return meta["locked_until"] @@ -30,7 +30,7 @@ def update_meta(update: dict[str, Any]) -> None: def update_meta_from_notes(notes: dict[str, dict[str, Any]]) -> None: update = { - "scraped_at": datetime.now(timezone.utc).isoformat(), + "scraped_at": datetime.now(UTC).isoformat(), "total_tweets": len({note["tweet_id"] for note in notes.values()}), "total_fetched": len( {note["tweet_id"] for note in notes.values() if "dl" in note} diff --git a/x_notes/notes.py b/x_notes/notes.py index 01a7946d..7c83050a 100644 --- a/x_notes/notes.py +++ b/x_notes/notes.py @@ -1,5 +1,5 @@ import re -from datetime import datetime, timedelta, timezone +from datetime import UTC, datetime, timedelta from typing import Any from urllib.parse import urlparse @@ -8,7 +8,7 @@ from .tsv import get_todays_data url_re = re.compile(r"https?:\/\/[^\s]+") -one_week_ago = (datetime.now(timezone.utc) - timedelta(days=7)).timestamp() +one_week_ago = (datetime.now(UTC) - timedelta(days=7)).timestamp() def urlize(inp: str) -> str: