{"id":44178,"date":"2025-08-07T14:45:30","date_gmt":"2025-08-07T05:45:30","guid":{"rendered":"https:\/\/techgym.jp\/?p=44178"},"modified":"2025-10-19T22:38:49","modified_gmt":"2025-10-19T13:38:49","slug":"python-calendar","status":"publish","type":"post","link":"https:\/\/techgym.jp\/column\/python-calendar\/","title":{"rendered":"Python calendar\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u30ab\u30ec\u30f3\u30c0\u30fc\u8868\u793a\u30fb\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u3010\u30c6\u30ad\u30b9\u30c8\u30fbHTML\u3011"},"content":{"rendered":"\n<p><iframe loading=\"lazy\" width=\"560\" height=\"314\" src=\"\/\/www.youtube.com\/embed\/7iX9nAJE0cE\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Python\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea<code>calendar<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u30c6\u30ad\u30b9\u30c8\u3084HTML\u5f62\u5f0f\u3067\u8868\u793a\u30fb\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u3092\u8a73\u3057\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u304b\u3089\u5fdc\u7528\u4f8b\u307e\u3067\u5e45\u5e83\u304f\u30ab\u30d0\u30fc\u3057\u307e\u3059\u3002<\/p>\n\n<h2>calendar\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u57fa\u672c<\/h2>\n<h3>\u57fa\u672c\u7684\u306a\u30ab\u30ec\u30f3\u30c0\u30fc\u8868\u793a<\/h3>\n<pre><code class=\"language-python\">import calendar\n\n# 2024\u5e741\u6708\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u8868\u793a\nyear = 2024\nmonth = 1\n\nprint(calendar.month(year, month))\n<\/code><\/pre>\n<h3>\u5e74\u9593\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u8868\u793a<\/h3>\n<pre><code class=\"language-python\">import calendar\n\n# 2024\u5e74\u306e\u5e74\u9593\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u8868\u793a\nyear = 2024\nprint(calendar.calendar(year))\n\n# \u5e45\u3092\u6307\u5b9a\u3057\u3066\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u8868\u793a\nprint(calendar.calendar(year, w=3, l=2, c=8))\n<\/code><\/pre>\n<h3>\u7279\u5b9a\u306e\u6708\u306e\u60c5\u5831\u53d6\u5f97<\/h3>\n<pre><code class=\"language-python\">import calendar\n\nyear = 2024\nmonth = 1\n\n# \u6708\u306e\u9031\u3068\u66dc\u65e5\u306e\u60c5\u5831\u3092\u53d6\u5f97\nmonth_calendar = calendar.monthcalendar(year, month)\nprint(\"\u6708\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\uff082\u6b21\u5143\u30ea\u30b9\u30c8\uff09:\")\nfor week in month_calendar:\n    print(week)\n\n# \u6708\u306e\u7bc4\u56f2\u3092\u53d6\u5f97\nweekday, days = calendar.monthrange(year, month)\nprint(f\"\\n{year}\u5e74{month}\u6708:\")\nprint(f\"1\u65e5\u306e\u66dc\u65e5: {weekday} (0=\u6708\u66dc)\")\nprint(f\"\u65e5\u6570: {days}\u65e5\")\n<\/code><\/pre>\n<h2>\u30c6\u30ad\u30b9\u30c8\u5f62\u5f0f\u306e\u30ab\u30ec\u30f3\u30c0\u30fc<\/h2>\n<h3>TextCalendar\u30af\u30e9\u30b9\u306e\u4f7f\u7528<\/h3>\n<pre><code class=\"language-python\">import calendar\n\n# TextCalendar\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\ncal = calendar.TextCalendar()\n\n# \u6708\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u53d6\u5f97\nmonth_str = cal.formatmonth(2024, 1)\nprint(\"TextCalendar\u306b\u3088\u308b\u6708\u8868\u793a:\")\nprint(month_str)\n\n# \u5e74\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u53d6\u5f97\nyear_str = cal.formatyear(2024)\nprint(\"\u5e74\u9593\u30ab\u30ec\u30f3\u30c0\u30fc\uff08\u4e00\u90e8\uff09:\")\nprint(year_str[:500] + \"...\")\n<\/code><\/pre>\n<h3>\u30ab\u30b9\u30bf\u30e0\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u306e\u30c6\u30ad\u30b9\u30c8\u30ab\u30ec\u30f3\u30c0\u30fc<\/h3>\n<pre><code class=\"language-python\">import calendar\n\nclass CustomTextCalendar(calendar.TextCalendar):\n    def formatday(self, day, weekday, width):\n        \"\"\"\u65e5\u4ed8\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\"\"\"\n        if day == 0:\n            s = ''\n        else:\n            s = f'{day:2d}'\n            \n        # \u571f\u66dc\u65e5\u3092\u9752\u8272\u3001\u65e5\u66dc\u65e5\u3092\u8d64\u8272\u3067\u8868\u793a\uff08\u8272\u306f\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u304c\u3001\u8a18\u53f7\u3067\u533a\u5225\uff09\n        if weekday == 5:  # \u571f\u66dc\u65e5\n            s = f'[{s}]'\n        elif weekday == 6:  # \u65e5\u66dc\u65e5\n            s = f'({s})'\n            \n        return s.rjust(width)\n\n# \u30ab\u30b9\u30bf\u30e0\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u4f7f\u7528\ncustom_cal = CustomTextCalendar()\nprint(\"\u30ab\u30b9\u30bf\u30e0\u30c6\u30ad\u30b9\u30c8\u30ab\u30ec\u30f3\u30c0\u30fc:\")\nprint(custom_cal.formatmonth(2024, 1))\n<\/code><\/pre>\n<h3>\u9031\u306e\u958b\u59cb\u66dc\u65e5\u3092\u5909\u66f4<\/h3>\n<pre><code class=\"language-python\">import calendar\n\n# \u6708\u66dc\u65e5\u59cb\u307e\u308a\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\uff09\ncal_mon = calendar.TextCalendar(firstweekday=calendar.MONDAY)\nprint(\"\u6708\u66dc\u65e5\u59cb\u307e\u308a:\")\nprint(cal_mon.formatmonth(2024, 1))\n\n# \u65e5\u66dc\u65e5\u59cb\u307e\u308a\ncal_sun = calendar.TextCalendar(firstweekday=calendar.SUNDAY)\nprint(\"\\n\u65e5\u66dc\u65e5\u59cb\u307e\u308a:\")\nprint(cal_sun.formatmonth(2024, 1))\n<\/code><\/pre>\n<h2>HTML\u5f62\u5f0f\u306e\u30ab\u30ec\u30f3\u30c0\u30fc<\/h2>\n<h3>HTMLCalendar\u30af\u30e9\u30b9\u306e\u57fa\u672c\u4f7f\u7528<\/h3>\n<pre><code class=\"language-python\">import calendar\n\n# HTMLCalendar\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\nhtml_cal = calendar.HTMLCalendar()\n\n# \u6708\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092HTML\u5f62\u5f0f\u3067\u53d6\u5f97\nhtml_month = html_cal.formatmonth(2024, 1)\nprint(\"HTML\u30ab\u30ec\u30f3\u30c0\u30fc:\")\nprint(html_month)\n<\/code><\/pre>\n<h3>\u30ab\u30b9\u30bf\u30e0HTML\u30ab\u30ec\u30f3\u30c0\u30fc<\/h3>\n<pre><code class=\"language-python\">import calendar\n\nclass CustomHTMLCalendar(calendar.HTMLCalendar):\n    def formatday(self, day, weekday):\n        \"\"\"\u65e5\u4ed8\u306eHTML\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\"\"\"\n        if day == 0:\n            return '&lt;td class=\"noday\"&gt;&amp;nbsp;&lt;\/td&gt;'\n        \n        # \u571f\u65e5\u306b\u7279\u5225\u306a\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\n        css_classes = []\n        if weekday == 5:  # \u571f\u66dc\u65e5\n            css_classes.append('saturday')\n        elif weekday == 6:  # \u65e5\u66dc\u65e5\n            css_classes.append('sunday')\n        \n        # \u4eca\u65e5\u306e\u65e5\u4ed8\u3092\u30cf\u30a4\u30e9\u30a4\u30c8\n        from datetime import date\n        today = date.today()\n        if day == today.day and today.year == 2024 and today.month == 1:\n            css_classes.append('today')\n        \n        class_attr = f' class=\"{\" \".join(css_classes)}\"' if css_classes else ''\n        return f'&lt;td{class_attr}&gt;{day}&lt;\/td&gt;'\n\n    def formatmonth(self, theyear, themonth, withyear=True):\n        \"\"\"\u6708\u306eHTML\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\"\"\"\n        cal = super().formatmonth(theyear, themonth, withyear)\n        \n        # CSS\u30b9\u30bf\u30a4\u30eb\u3092\u8ffd\u52a0\n        style = \"\"\"\n        &lt;style&gt;\n        .calendar {\n            border-collapse: collapse;\n            margin: 20px auto;\n        }\n        .calendar td, .calendar th {\n            border: 1px solid #ddd;\n            padding: 8px;\n            text-align: center;\n        }\n        .saturday { background-color: #e6f3ff; }\n        .sunday { background-color: #ffe6e6; }\n        .today { background-color: #ffff99; font-weight: bold; }\n        .noday { background-color: #f5f5f5; }\n        &lt;\/style&gt;\n        \"\"\"\n        \n        # \u30c6\u30fc\u30d6\u30eb\u306b\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\n        cal = cal.replace('&lt;table', '&lt;table class=\"calendar\"')\n        return style + cal\n\n# \u30ab\u30b9\u30bf\u30e0HTML\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u4f7f\u7528\ncustom_html_cal = CustomHTMLCalendar()\nhtml_with_style = custom_html_cal.formatmonth(2024, 1)\nprint(\"\u30b9\u30bf\u30a4\u30eb\u4ed8\u304dHTML\u30ab\u30ec\u30f3\u30c0\u30fc:\")\nprint(html_with_style)\n<\/code><\/pre>\n<h3>HTML\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u4fdd\u5b58<\/h3>\n<pre><code class=\"language-python\">import calendar\nfrom datetime import date\n\ndef generate_html_calendar_file(year, month, filename=None):\n    \"\"\"HTML\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u4fdd\u5b58\"\"\"\n    if filename is None:\n        filename = f\"calendar_{year}_{month:02d}.html\"\n    \n    html_cal = calendar.HTMLCalendar()\n    \n    # HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\n    html_template = f\"\"\"\n    &lt;!DOCTYPE html&gt;\n    &lt;html lang=\"ja\"&gt;\n    &lt;head&gt;\n        &lt;meta charset=\"UTF-8\"&gt;\n        &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n        &lt;title&gt;{year}\u5e74{month}\u6708\u30ab\u30ec\u30f3\u30c0\u30fc&lt;\/title&gt;\n        &lt;style&gt;\n            body {{\n                font-family: Arial, sans-serif;\n                margin: 20px;\n                background-color: #f0f0f0;\n            }}\n            .calendar {{\n                border-collapse: collapse;\n                margin: 20px auto;\n                background-color: white;\n                box-shadow: 0 2px 10px rgba(0,0,0,0.1);\n            }}\n            .calendar th, .calendar td {{\n                border: 1px solid #ddd;\n                padding: 10px;\n                text-align: center;\n                width: 40px;\n                height: 40px;\n            }}\n            .calendar th {{\n                background-color: #4CAF50;\n                color: white;\n                font-weight: bold;\n            }}\n            .calendar .sat {{\n                background-color: #e3f2fd;\n            }}\n            .calendar .sun {{\n                background-color: #ffebee;\n            }}\n            h1 {{\n                text-align: center;\n                color: #333;\n            }}\n        &lt;\/style&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;h1&gt;{year}\u5e74{month}\u6708&lt;\/h1&gt;\n        {html_cal.formatmonth(year, month)}\n    &lt;\/body&gt;\n    &lt;\/html&gt;\n    \"\"\"\n    \n    with open(filename, 'w', encoding='utf-8') as f:\n        f.write(html_template)\n    \n    print(f\"HTML\u30ab\u30ec\u30f3\u30c0\u30fc\u3092'{filename}'\u306b\u4fdd\u5b58\u3057\u307e\u3057\u305f\")\n\n# HTML\u30d5\u30a1\u30a4\u30eb\u306e\u751f\u6210\ngenerate_html_calendar_file(2024, 1)\n<\/code><\/pre>\n<h2>\u5b9f\u7528\u7684\u306a\u5fdc\u7528\u4f8b<\/h2>\n<h3>\u30a4\u30d9\u30f3\u30c8\u4ed8\u304d\u30ab\u30ec\u30f3\u30c0\u30fc<\/h3>\n<pre><code class=\"language-python\">import calendar\nfrom datetime import date\n\nclass EventCalendar(calendar.HTMLCalendar):\n    def __init__(self, events=None):\n        super().__init__()\n        self.events = events or {}\n    \n    def formatday(self, day, weekday):\n        \"\"\"\u30a4\u30d9\u30f3\u30c8\u60c5\u5831\u4ed8\u304d\u306e\u65e5\u4ed8\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\"\"\"\n        if day == 0:\n            return '&lt;td class=\"noday\"&gt;&amp;nbsp;&lt;\/td&gt;'\n        \n        # \u30a4\u30d9\u30f3\u30c8\u304c\u3042\u308b\u304b\u30c1\u30a7\u30c3\u30af\n        event_text = self.events.get(day, '')\n        event_class = ' event' if event_text else ''\n        \n        # \u571f\u65e5\u306e\u30af\u30e9\u30b9\n        weekend_class = ''\n        if weekday == 5:\n            weekend_class = ' saturday'\n        elif weekday == 6:\n            weekend_class = ' sunday'\n        \n        return f'&lt;td class=\"day{weekend_class}{event_class}\" title=\"{event_text}\"&gt;{day}&lt;\/td&gt;'\n\n# \u30a4\u30d9\u30f3\u30c8\u30c7\u30fc\u30bf\u306e\u4f8b\nevents = {\n    1: \"\u65b0\u5e74\",\n    15: \"\u4f1a\u8b70\",\n    25: \"\u30d7\u30ec\u30bc\u30f3\u30c6\u30fc\u30b7\u30e7\u30f3\"\n}\n\n# \u30a4\u30d9\u30f3\u30c8\u4ed8\u304d\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u751f\u6210\nevent_cal = EventCalendar(events)\nhtml_calendar = event_cal.formatmonth(2024, 1)\n\n# \u30b9\u30bf\u30a4\u30eb\u4ed8\u304dHTML\u3068\u3057\u3066\u51fa\u529b\nfull_html = f\"\"\"\n&lt;style&gt;\n.calendar {{ border-collapse: collapse; margin: 20px auto; }}\n.calendar td, .calendar th {{ border: 1px solid #ddd; padding: 8px; text-align: center; }}\n.saturday {{ background-color: #e6f3ff; }}\n.sunday {{ background-color: #ffe6e6; }}\n.event {{ background-color: #fff2cc; font-weight: bold; }}\n&lt;\/style&gt;\n{html_calendar}\n\"\"\"\nprint(\"\u30a4\u30d9\u30f3\u30c8\u4ed8\u304d\u30ab\u30ec\u30f3\u30c0\u30fc:\")\nprint(full_html)\n<\/code><\/pre>\n<h3>\u8907\u6570\u6708\u8868\u793a\u30ab\u30ec\u30f3\u30c0\u30fc<\/h3>\n<pre><code class=\"language-python\">import calendar\n\ndef generate_multi_month_calendar(year, start_month, num_months):\n    \"\"\"\u8907\u6570\u6708\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u751f\u6210\"\"\"\n    cal = calendar.TextCalendar()\n    \n    print(f\"=== {year}\u5e74 {start_month}\u6708\u301c{start_month + num_months - 1}\u6708 ===\\n\")\n    \n    for i in range(num_months):\n        month = start_month + i\n        if month &gt; 12:\n            month = month - 12\n            year += 1\n        \n        print(f\"{year}\u5e74{month}\u6708\")\n        print(\"=\" * 20)\n        print(cal.formatmonth(year, month))\n        print()\n\n# 3\u30f6\u6708\u5206\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u8868\u793a\ngenerate_multi_month_calendar(2024, 1, 3)\n<\/code><\/pre>\n<h3>\u795d\u65e5\u5bfe\u5fdc\u30ab\u30ec\u30f3\u30c0\u30fc<\/h3>\n<pre><code class=\"language-python\">import calendar\n\nclass JapaneseHolidayCalendar(calendar.TextCalendar):\n    def __init__(self):\n        super().__init__()\n        # \u7c21\u7565\u5316\u3057\u305f\u795d\u65e5\u30c7\u30fc\u30bf\n        self.holidays = {\n            (1, 1): \"\u5143\u65e5\",\n            (2, 11): \"\u5efa\u56fd\u8a18\u5ff5\u306e\u65e5\",\n            (4, 29): \"\u662d\u548c\u306e\u65e5\",\n            (5, 3): \"\u61b2\u6cd5\u8a18\u5ff5\u65e5\",\n            (5, 4): \"\u307f\u3069\u308a\u306e\u65e5\",\n            (5, 5): \"\u3053\u3069\u3082\u306e\u65e5\",\n        }\n    \n    def formatday(self, day, weekday, width):\n        \"\"\"\u795d\u65e5\u3092\u8003\u616e\u3057\u305f\u65e5\u4ed8\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\"\"\"\n        if day == 0:\n            return ''.rjust(width)\n        \n        # \u795d\u65e5\u30c1\u30a7\u30c3\u30af\n        holiday = self.holidays.get((1, day))  # 1\u6708\u306e\u4f8b\n        if holiday:\n            return f'{day:2d}*'.rjust(width)  # \u795d\u65e5\u306b*\u3092\u4ed8\u3051\u308b\n        elif weekday == 6:  # \u65e5\u66dc\u65e5\n            return f'{day:2d}\u300f'.rjust(width)\n        elif weekday == 5:  # \u571f\u66dc\u65e5\n            return f'{day:2d}\u300f'.rjust(width)\n        else:\n            return f'{day:2d}'.rjust(width)\n\n# \u795d\u65e5\u5bfe\u5fdc\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u8868\u793a\nholiday_cal = JapaneseHolidayCalendar()\nprint(\"\u795d\u65e5\u5bfe\u5fdc\u30ab\u30ec\u30f3\u30c0\u30fc\uff08*=\u795d\u65e5\uff09:\")\nprint(holiday_cal.formatmonth(2024, 1))\n<\/code><\/pre>\n<h3>\u30ab\u30ec\u30f3\u30c0\u30fc\u60c5\u5831\u306e\u62bd\u51fa<\/h3>\n<pre><code class=\"language-python\">import calendar\nfrom datetime import date, timedelta\n\ndef calendar_statistics(year, month):\n    \"\"\"\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u7d71\u8a08\u60c5\u5831\u3092\u53d6\u5f97\"\"\"\n    # \u6708\u306e\u57fa\u672c\u60c5\u5831\n    weekday_start, days_in_month = calendar.monthrange(year, month)\n    \n    # \u66dc\u65e5\u3054\u3068\u306e\u65e5\u6570\u3092\u30ab\u30a6\u30f3\u30c8\n    weekday_counts = [0] * 7\n    \n    for day in range(1, days_in_month + 1):\n        dt = date(year, month, day)\n        weekday_counts[dt.weekday()] += 1\n    \n    weekday_names = ['\u6708', '\u706b', '\u6c34', '\u6728', '\u91d1', '\u571f', '\u65e5']\n    \n    print(f\"=== {year}\u5e74{month}\u6708\u306e\u7d71\u8a08 ===\")\n    print(f\"\u7dcf\u65e5\u6570: {days_in_month}\u65e5\")\n    print(f\"1\u65e5\u306e\u66dc\u65e5: {weekday_names[weekday_start]}\u66dc\u65e5\")\n    print(\"\\n\u66dc\u65e5\u5225\u65e5\u6570:\")\n    for i, count in enumerate(weekday_counts):\n        print(f\"  {weekday_names[i]}\u66dc\u65e5: {count}\u65e5\")\n    \n    # \u9031\u672b\u306e\u65e5\u6570\n    weekend_days = weekday_counts[5] + weekday_counts[6]\n    business_days = days_in_month - weekend_days\n    print(f\"\\n\u55b6\u696d\u65e5: {business_days}\u65e5\")\n    print(f\"\u9031\u672b: {weekend_days}\u65e5\")\n    \n    return {\n        'total_days': days_in_month,\n        'weekday_counts': weekday_counts,\n        'business_days': business_days,\n        'weekend_days': weekend_days\n    }\n\n# \u7d71\u8a08\u60c5\u5831\u306e\u8868\u793a\nstats = calendar_statistics(2024, 1)\n<\/code><\/pre>\n<h3>\u30ab\u30ec\u30f3\u30c0\u30fc\u30c7\u30fc\u30bf\u306e\u30a8\u30af\u30b9\u30dd\u30fc\u30c8<\/h3>\n<pre><code class=\"language-python\">import calendar\nimport json\nfrom datetime import date\n\ndef export_calendar_data(year, month, format='json'):\n    \"\"\"\u30ab\u30ec\u30f3\u30c0\u30fc\u30c7\u30fc\u30bf\u3092\u6307\u5b9a\u5f62\u5f0f\u3067\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\"\"\"\n    month_calendar = calendar.monthcalendar(year, month)\n    \n    calendar_data = {\n        'year': year,\n        'month': month,\n        'month_name': calendar.month_name[month],\n        'weeks': []\n    }\n    \n    weekday_names = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', \n                    'Friday', 'Saturday', 'Sunday']\n    \n    for week in month_calendar:\n        week_data = []\n        for i, day in enumerate(week):\n            if day == 0:\n                week_data.append(None)\n            else:\n                day_info = {\n                    'day': day,\n                    'weekday': weekday_names[i],\n                    'is_weekend': i &gt;= 5\n                }\n                week_data.append(day_info)\n        calendar_data['weeks'].append(week_data)\n    \n    if format == 'json':\n        filename = f'calendar_{year}_{month:02d}.json'\n        with open(filename, 'w', encoding='utf-8') as f:\n            json.dump(calendar_data, f, ensure_ascii=False, indent=2)\n        print(f\"JSON\u30c7\u30fc\u30bf\u3092'{filename}'\u306b\u4fdd\u5b58\u3057\u307e\u3057\u305f\")\n    \n    return calendar_data\n\n# \u30ab\u30ec\u30f3\u30c0\u30fc\u30c7\u30fc\u30bf\u306e\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\ncalendar_data = export_calendar_data(2024, 1)\nprint(\"\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306e\u4e00\u90e8:\")\nprint(json.dumps(calendar_data['weeks'][0], ensure_ascii=False, indent=2))\n<\/code><\/pre>\n<h2>\u307e\u3068\u3081<\/h2>\n<ul>\n<li><strong>\u57fa\u672c\u6a5f\u80fd<\/strong>\uff1a<code>calendar.month()<\/code>, <code>calendar.calendar()<\/code>, <code>monthcalendar()<\/code><\/li>\n<li><strong>\u30c6\u30ad\u30b9\u30c8\u51fa\u529b<\/strong>\uff1a<code>TextCalendar<\/code>\u30af\u30e9\u30b9\u3067\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u53ef\u80fd<\/li>\n<li><strong>HTML\u51fa\u529b<\/strong>\uff1a<code>HTMLCalendar<\/code>\u30af\u30e9\u30b9\u3067Web\u30da\u30fc\u30b8\u751f\u6210<\/li>\n<li><strong>\u5b9f\u7528\u4f8b<\/strong>\uff1a\u30a4\u30d9\u30f3\u30c8\u4ed8\u304d\u30ab\u30ec\u30f3\u30c0\u30fc\u3001\u795d\u65e5\u5bfe\u5fdc\u3001\u7d71\u8a08\u60c5\u5831<\/li>\n<li><strong>\u30c7\u30fc\u30bf\u5f62\u5f0f<\/strong>\uff1aJSON\u3001HTML\u3001\u30c6\u30ad\u30b9\u30c8\u3067\u306e\u30a8\u30af\u30b9\u30dd\u30fc\u30c8<\/li>\n<\/ul>\n<p>calendar\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u69d8\u3005\u306a\u5f62\u5f0f\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u8868\u793a\u30fb\u51fa\u529b\u304c\u52b9\u7387\u7684\u306b\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0<a href=\"https:\/\/amzn.to\/3VxGkpx\">\u300c\u3089\u304f\u3089\u304fPython\u587e\u300d\u304c\u5207\u308a\u958b\u304f\u300c\u546a\u6587\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u300d\u3068\u306f\uff1f<\/a><\/h2>\n\n\n\n<p><iframe loading=\"lazy\" width=\"560\" height=\"314\" src=\"\/\/www.youtube.com\/embed\/7iX9nAJE0cE\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"4bYvaBINkc\"><a href=\"https:\/\/techgym.jp\/about\/rakurakupython\/\">\u3010\u9769\u547d\u7684\u5b66\u7fd2\u6cd5\u3011\u300c\u3089\u304f\u3089\u304fPython\u587e\u300d\u304c\u5207\u308a\u958b\u304f\u3001\u546a\u6587\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3068\u3044\u3046\u65b0\u6642\u4ee3\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7fd2\u5f97\u8853<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u3010\u9769\u547d\u7684\u5b66\u7fd2\u6cd5\u3011\u300c\u3089\u304f\u3089\u304fPython\u587e\u300d\u304c\u5207\u308a\u958b\u304f\u3001\u546a\u6587\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3068\u3044\u3046\u65b0\u6642\u4ee3\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7fd2\u5f97\u8853&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/about\/rakurakupython\/embed\/#?secret=ALvyYx1NIO#?secret=4bYvaBINkc\" data-secret=\"4bYvaBINkc\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u25a0\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"pRDun6wrbo\"><a href=\"https:\/\/techgym.jp\/column\/ori-app\/\">\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/column\/ori-app\/embed\/#?secret=VmxgRWtq04#?secret=pRDun6wrbo\" data-secret=\"pRDun6wrbo\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u25a0AI\u6642\u4ee3\u306e\u7b2c\u4e00\u6b69\uff01\u300cAI\u99c6\u52d5\u958b\u767a\u30b3\u30fc\u30b9\u300d\u306f\u3058\u3081\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<p>\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821\u3067\u5148\u884c\u958b\u59cb\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"ntghQhbqT5\"><a href=\"https:\/\/techgym.jp\/about\/ai-driven-development\/\">AI\u99c6\u52d5\u958b\u767a\/\u751f\u6210AI\u30a8\u30f3\u30b8\u30cb\u30a2\u30b3\u30fc\u30b9\uff08\u521d\u5fc3\u8005\u5411\u3051\uff09<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;AI\u99c6\u52d5\u958b\u767a\/\u751f\u6210AI\u30a8\u30f3\u30b8\u30cb\u30a2\u30b3\u30fc\u30b9\uff08\u521d\u5fc3\u8005\u5411\u3051\uff09&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/about\/ai-driven-development\/embed\/#?secret=hltxz4jUIq#?secret=ntghQhbqT5\" data-secret=\"ntghQhbqT5\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u25a0\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821<\/p>\n\n\n\n<p>\u300c\u6b66\u7530\u587e\u300d\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7248\u3068\u3044\u3048\u3070\u300c\u30c6\u30c3\u30af\u30b8\u30e0\u300d\u3002<br>\u8b1b\u7fa9\u52d5\u753b\u306a\u3057\u3001\u6559\u79d1\u66f8\u306a\u3057\u3002\u300c\u9032\u6357\u7ba1\u7406\u3068\u30b3\u30fc\u30c1\u30f3\u30b0\u300d\u3067\u52b9\u7387\u5b66\u7fd2\u3002<br>\u3088\u308a\u65e9\u304f\u3001\u3088\u308a\u5b89\u304f\u3001\u3057\u304b\u3082\u5bfe\u9762\u578b\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\u3067\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"Beor3CqSSk\"><a href=\"https:\/\/techgym.jp\/tokyo\/tokyo_honko\/\">\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/tokyo\/tokyo_honko\/embed\/#?secret=go2NM5d1nm#?secret=Beor3CqSSk\" data-secret=\"Beor3CqSSk\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u77ed\u671f\u8b1b\u7fd2\uff1e5\u65e5\u30675\u4e07\u5186\u306e\u300cPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u958b\u50ac\u4e2d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"C1qUqzoTuf\"><a href=\"https:\/\/techgym.jp\/event\/nagatacho_camp\/\">\u3010\u6700\u901f\u30fb\u78ba\u5b9f\u3011\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u653b\u7565\u300c\u6c38\u7530\u753aPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u30105\u65e5\u9593\u30675\u4e07\u5186\u3011<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u3010\u6700\u901f\u30fb\u78ba\u5b9f\u3011\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u653b\u7565\u300c\u6c38\u7530\u753aPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u30105\u65e5\u9593\u30675\u4e07\u5186\u3011&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/event\/nagatacho_camp\/embed\/#?secret=gtzZTT5Tyq#?secret=C1qUqzoTuf\" data-secret=\"C1qUqzoTuf\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u67081\u958b\u50ac\uff1e\u653e\u9001\u4f5c\u5bb6\u306b\u3088\u308b\u6620\u50cf\u30c7\u30a3\u30ec\u30af\u30bf\u30fc\u990a\u6210\u8b1b\u5ea7<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"WxD9FRpeiC\"><a href=\"https:\/\/techgym.jp\/event\/video_director\/\">\u73fe\u5f79\u653e\u9001\u4f5c\u5bb6\u304c\u6559\u3048\u308b\u52d5\u753b\u8b1b\u5ea7\uff01\u300e\uff24\uff2f\uff27\uff21\u300f<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u73fe\u5f79\u653e\u9001\u4f5c\u5bb6\u304c\u6559\u3048\u308b\u52d5\u753b\u8b1b\u5ea7\uff01\u300e\uff24\uff2f\uff27\uff21\u300f&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/event\/video_director\/embed\/#?secret=U3rXEgWrFT#?secret=WxD9FRpeiC\" data-secret=\"WxD9FRpeiC\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u30aa\u30f3\u30e9\u30a4\u30f3\u7121\u6599\uff1e\u30bc\u30ed\u304b\u3089\u59cb\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"YGkpCNa3VL\"><a href=\"https:\/\/techgym.jp\/tokyo_python\/\">\u3010\u7121\u6599\u30fb\u30aa\u30f3\u30e9\u30a4\u30f3\u3011\u30bc\u30ed\u304b\u3089\u306f\u3058\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u3010\u7121\u6599\u30fb\u30aa\u30f3\u30e9\u30a4\u30f3\u3011\u30bc\u30ed\u304b\u3089\u306f\u3058\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/tokyo_python\/embed\/#?secret=D89c6GkaMc#?secret=YGkpCNa3VL\" data-secret=\"YGkpCNa3VL\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Python\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30eacalendar\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u30c6\u30ad\u30b9\u30c8\u3084HTML\u5f62\u5f0f\u3067\u8868\u793a\u30fb\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u3092\u8a73\u3057\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u304b\u3089\u5fdc\u7528\u4f8b\u307e\u3067\u5e45\u5e83\u304f\u30ab\u30d0\u30fc\u3057\u307e\u3059\u3002 calendar\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u57fa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":42501,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-44178","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-column"],"views":111,"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/07\/f3403acf5c65aedec0dba821c4c26404.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts\/44178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/comments?post=44178"}],"version-history":[{"count":0,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts\/44178\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/media\/42501"}],"wp:attachment":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/media?parent=44178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/categories?post=44178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/tags?post=44178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}