6 month calendar view


A little new to Python, I’m hoping it can help me automating a process I have.
Every year I build a series of calendars looking like this:

and fill in colors on specific dates, based on a CSV file (and patch Tuesdays).

My main problem is how do I create a calendar with a 6 month view like the one in the picture?

Would this help?


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 will however have another look at it.

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… :wink:

I will be using the calendar library to place the day of the week and weekdays correctly.

Very early version. Python is fun. :wink:

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]
        weeknumber = ""
    if day == second_tuesday:
        data = "Patch Tuesday!"
        data = ""
    print ("|", weekday, "|" , day , "|", data, "|", weeknumber, "|")
    day += 1