Exemple #1
0
def format_month(year, month, day=-1):
    """Format a calendar for a given month, highlight the day if given"""
    week_header = " Mo Tu We Th Fr Sa Su "
    spaces = len(week_header) - len(months[month])
    right = spaces / 2
    left = spaces - right
    month_str = " " * left + months[month] + " " * right
    ret = [month_str, week_header]
    line = " "
    curr_day = jdn(year, month, 1) % 7

    for i in range(curr_day):
        line += "   "

    for i in range(day_months[month]):
        if i + 1 == day:
            line = line[:-1] + "[%2i]" % (i+1)
        else:
            line += "%2i " % (i+1)
        curr_day += 1
        if curr_day == 7:
            ret.append(line)
            line = " "
            curr_day = 0

    for i in range(curr_day, 7):
        line += "   "
    ret.append(line)

    return ret
def fridays():
    month = 3
    year = 2009

    thirteenths = []
    for i in range(120):
        month += 1
        if month > 12:
            month -= 12
            year += 1
        if jdn(year, month, 13) % 7 == 4:
            thirteenths.append((year, month))
    return len(thirteenths)