Meta: Port several things common to various Python scripts to a new website module

This commit is contained in:
Eryn Wells 2024-11-17 14:49:33 -08:00
parent a30903c8cf
commit 9ce6362402
6 changed files with 70 additions and 34 deletions

View file

@ -6,34 +6,8 @@ import datetime
import os.path
import subprocess
from typing import Optional
def content_path() -> str:
from os.path import abspath, dirname, join
return abspath(join(dirname(__file__), '..', 'content'))
def next_sunday_noon() -> datetime.datetime:
today = datetime.date.today()
current_weekday = today.weekday()
if current_weekday == 6:
days_to_next_sunday = 6
else:
days_to_next_sunday = 6 - current_weekday
delta = datetime.timedelta(days=days_to_next_sunday)
noon = datetime.time(hour=12)
timezone = datetime.datetime.now().astimezone().tzinfo
next_sunday_noon = datetime.datetime.combine(
today + delta,
noon,
tzinfo=timezone
)
return next_sunday_noon
from website.dates import next_sunday_noon
from website.paths import content_path
def weeknotes_path(*, week_number: Optional[int] = None):