Skip to content

Commit

Permalink
Replace deprecated utcnow() with now(utc) (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored May 16, 2023
2 parents 5a1698d + 2fc6ebd commit 159c843
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/norwegianblue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _colourify(data: list[dict]) -> list[dict]:
yellow: will pass in six months
green: will pass after six months
"""
now = dt.datetime.utcnow()
now = dt.datetime.now(dt.timezone.utc)
six_months_from_now = now + relativedelta(months=+6)

for cycle in data:
Expand All @@ -153,7 +153,9 @@ def _colourify(data: list[dict]) -> list[dict]:
# Handle date
date_str = cycle[property_]
# Convert "2020-01-01" string to datetime
date_datetime = dt.datetime.strptime(date_str, "%Y-%m-%d")
date_datetime = dt.datetime.strptime(date_str, "%Y-%m-%d").replace(
tzinfo=dt.timezone.utc
)
if date_datetime < now:
cycle[property_] = colored(date_str, "red")
elif date_datetime < six_months_from_now:
Expand Down
4 changes: 2 additions & 2 deletions src/norwegianblue/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def filename(url: str) -> Path:
"""yyyy-mm-dd-url-slug.json"""
from slugify import slugify

today = dt.datetime.utcnow().strftime("%Y-%m-%d")
today = dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%d")
slug = slugify(url)
return CACHE_DIR / f"{today}-{slug}.json"

Expand Down Expand Up @@ -51,7 +51,7 @@ def save(cache_file: Path, data) -> None:
def clear(clear_all: bool = False) -> None:
"""Delete all or old cache files"""
cache_files = CACHE_DIR.glob("**/*.json")
today = dt.datetime.utcnow().strftime("%Y-%m-%d")
today = dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%d")
for cache_file in cache_files:
if clear_all or not cache_file.name.startswith(today):
cache_file.unlink()

0 comments on commit 159c843

Please sign in to comment.