Print a calendar for a given year.
(year)
| 18 | |
| 19 | |
| 20 | def print_calendar(year): |
| 21 | """Print a calendar for a given year.""" |
| 22 | |
| 23 | today = datetime.today() |
| 24 | year = int(year) |
| 25 | cal = calendar.Calendar() |
| 26 | today_tuple = today.day, today.month, today.year |
| 27 | |
| 28 | tables = [] |
| 29 | |
| 30 | for month in range(1, 13): |
| 31 | table = Table( |
| 32 | title=f"{calendar.month_name[month]} {year}", |
| 33 | style="green", |
| 34 | box=box.SIMPLE_HEAVY, |
| 35 | padding=0, |
| 36 | ) |
| 37 | |
| 38 | for week_day in cal.iterweekdays(): |
| 39 | table.add_column( |
| 40 | "{:.3}".format(calendar.day_name[week_day]), justify="right" |
| 41 | ) |
| 42 | |
| 43 | month_days = cal.monthdayscalendar(year, month) |
| 44 | for weekdays in month_days: |
| 45 | days = [] |
| 46 | for index, day in enumerate(weekdays): |
| 47 | day_label = Text(str(day or ""), style="magenta") |
| 48 | if index in (5, 6): |
| 49 | day_label.stylize("blue") |
| 50 | if day and (day, month, year) == today_tuple: |
| 51 | day_label.stylize("white on dark_red") |
| 52 | days.append(day_label) |
| 53 | table.add_row(*days) |
| 54 | |
| 55 | tables.append(Align.center(table)) |
| 56 | |
| 57 | console = Console() |
| 58 | columns = Columns(tables, padding=1, expand=True) |
| 59 | console.rule(str(year)) |
| 60 | console.print() |
| 61 | console.print(columns) |
| 62 | console.rule(str(year)) |
| 63 | |
| 64 | |
| 65 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…