From 7843ee9cdd9864c25a0c4f9270ec629a3d1f952c Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 3 Jun 2024 07:55:36 -0700 Subject: [PATCH] Write a new script to calculate next Sunday's date --- Makefile | 2 +- scripts/next_sunday.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 scripts/next_sunday.py diff --git a/Makefile b/Makefile index f4b0b41..31cc605 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ nethack-commit: $(NETHACK_LOGFILE_DATA_FILE) weeknotes: YEAR=$(shell date '+%Y') weeknotes: WEEK_NUMBER=$(shell date '+%V') -weeknotes: UPCOMING_SUNDAY=$(shell date -v +Sun +%FT%T%z) +weeknotes: UPCOMING_SUNDAY=$(shell scripts/next_sunday.py) weeknotes: PAGE_PATH=blog/$(YEAR)/weeknotes-$(YEAR)w$(WEEK_NUMBER).md weeknotes: $(CONTENT_PATH)/$(PAGE_PATH) hugo new -k weeknotes --clock "$(UPCOMING_SUNDAY)" -c "$(CONTENT_PATH)" "$(PAGE_PATH)" diff --git a/scripts/next_sunday.py b/scripts/next_sunday.py new file mode 100755 index 0000000..f614993 --- /dev/null +++ b/scripts/next_sunday.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import datetime +import time +import zoneinfo + +def main(): + 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 + ) + + print(next_sunday_noon.isoformat()) + + return 0 + +if __name__ == "__main__": + main()