Skip to content

Commit

Permalink
chore: timezone.utc -> UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed Aug 12, 2024
1 parent 9294038 commit e057475
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions x_notes/health_check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from io import BytesIO

import requests
Expand All @@ -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.")
Expand Down
4 changes: 2 additions & 2 deletions x_notes/helpers.py
Original file line number Diff line number Diff line change
@@ -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]]:
Expand Down
6 changes: 3 additions & 3 deletions x_notes/meta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Any


Expand All @@ -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"]

Expand All @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions x_notes/notes.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down

0 comments on commit e057475

Please sign in to comment.