Write a new script to calculate next Sunday's date
This commit is contained in:
parent
e2d64f82f8
commit
7843ee9cdd
2 changed files with 33 additions and 1 deletions
2
Makefile
2
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)"
|
||||
|
|
32
scripts/next_sunday.py
Executable file
32
scripts/next_sunday.py
Executable file
|
@ -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()
|
Loading…
Add table
Add a link
Reference in a new issue