view wall_calendar.py @ 79:30ad34850ef1

redo url structure (still not the same as the old version)
author drewp@bigasterisk.com
date Fri, 06 Sep 2024 18:24:38 -0700
parents ab54c9f65f76
children
line wrap: on
line source

"""
also see https://madebyevan.com/calendar/app/
https://ui.toast.com/tui-calendar
"""
import calendar
import datetime
import itertools
import sys

from htmlgenerator import BODY, H1, HEAD, HTML, SPAN, STYLE, TABLE, TBODY, TD, TH, TR, mark_safe, render

c = calendar.TextCalendar(firstweekday=6)

start = datetime.date.today()
start = start - datetime.timedelta(days=start.weekday() + 1)
offset = itertools.count()
currentMonth = -1


def nextDayLabel():
    global currentMonth
    thisDay = start + datetime.timedelta(days=next(offset))
    month = ''
    if thisDay.month != currentMonth:
        month = f'{calendar.month_name[thisDay.month]} '
        currentMonth = thisDay.month
    return f'{month}{thisDay.day}'


def weekdayLabels():
    row = [TH(c.formatweekday(i, width=100)) for i in c.iterweekdays()]
    return TR(*row)


def nextWeekDays():
    return TR(*[TD(SPAN(nextDayLabel(), class_="day")) for wd in c.iterweekdays()])


sys.stdout.write(
    render(
        HTML(  #
            HEAD(STYLE(mark_safe(open('wall_calendar.css').read()))),  #
            BODY(H1("todo"), TABLE(*weekdayLabels(), TBODY(*[nextWeekDays() for week in range(8)])))),
        {}))