かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】



このエントリーをはてなブックマークに追加
カレンダー(calendar.monthcalendar)

#! /usr/bin/python
# coding: Shift_JIS

import time
import calendar

year, mon = time.localtime()[:2]
calendar.setfirstweekday(6)

print "Content-type: text/html"
print """
    <html>
    <head>
    <title>カレンダー %d年%d月</title>
    </head>
    <body>
    <table border="1" bordercolor="#9933ff" cellspacing="0" cellpadding="5">
    <tr><td colspan="7" align="center">%d<small>年</small>%d<small>月</small></td></tr>
""" % (year, mon, year, mon)

print "<tr>"
for s in ['日', '月', '火', '水', '木', '金', '土']:
    print "<td align=\"center\"><small>%s</small></td>" % s
print "</tr>"

for week in calendar.monthcalendar(year, mon):
    print "<tr>"
    for day in week:
        print "<td align=\"right\">"
        if day:    print day
        else:    print " "
        print "</td>"
    print "</tr>"

print """
    </table>
    </body>
    </html>
"""
かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】