MCPcopy
hub / github.com/Textualize/rich / print_calendar

Function print_calendar

examples/print_calendar.py:20–62  ·  view source on GitHub ↗

Print a calendar for a given year.

(year)

Source from the content-addressed store, hash-verified

18
19
20def 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
65if __name__ == "__main__":

Callers 1

print_calendar.pyFile · 0.85

Calls 11

add_columnMethod · 0.95
stylizeMethod · 0.95
add_rowMethod · 0.95
ruleMethod · 0.95
printMethod · 0.95
TableClass · 0.90
TextClass · 0.90
ConsoleClass · 0.90
ColumnsClass · 0.90
centerMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…