I should have mentioned that I have had a look at “Calendar” as I understand it, it will output a calendar in the Unix Cal format: cal (Unix) - Wikipedia
And maybe I should have a closer look, but I can not quite figure out how to convert it into the format I posted.
I’m looking into creating a huge CSS grid to fit my calendar… Setting it up the first time will be a huge challenge, but once it’s done I’ll be able to address any field, the dates (numbers) will be fixed (except 27/2) and Python will then fill in the day of the week and week numbers and patch Tuesdays.
Once that is done I either need to add my CSV file with the rest of the dates or simply bypass the CSV and read directly from the source…
I will be using the calendar library to place the day of the week and weekdays correctly.
import calendar
import datetime
def PatchTuesday(year, month):
c = calendar.Calendar(firstweekday=calendar.MONDAY)
monthcal = c.monthdatescalendar(year, month)
second_tuesday = [day for week in monthcal for day in week if \
day.weekday() == calendar.TUESDAY and \
day.month == month][1].day
return second_tuesday
Month = 12
Year = 2021
#Range of month, First and last day og the month. daymax returns last day og the month.
daymax = calendar.monthrange(Year,Month)[1]
second_tuesday = PatchTuesday(Year, Month)
#reset While loop to first day of the month (always 1) ;-)
day = 1
while day <= daymax:
weekday = calendar.day_abbr[calendar.weekday(Year, Month, day)]
if calendar.weekday(Year, Month, day) == 0:
weeknumber = datetime.date(Year, Month, day).isocalendar()[1]
else:
weeknumber = ""
if day == second_tuesday:
data = "Patch Tuesday!"
else:
data = ""
print ("|", weekday, "|" , day , "|", data, "|", weeknumber, "|")
day += 1