Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Python by pcal ( 5 years ago )
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import datetime
import calendar
import urllib.request, urllib.error
import re


response = urllib.request.urlopen('https://calendar.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics')
html = response.read().decode('utf-8')

'''
*** 祝日対応カレンダー
*** python 3.6.8
*** conky
*** color2 FF0000   祝・休日
*** color5 00FFFF   土
*** color6 FFFF00   今日
*** color7 FFFFFF   平日
*** 年月は直前の色(お好みで)
'''
def get_holiday(year, month):
    holiday = []
    str = "{:04d}{:02d}".format(year, month)
    for m in html.splitlines():
        if re.search(str, m):
            if re.search('DTSTART', m):
                holiday.append(int(m[-2:]))
    return holiday

def make_calendar(year, month, day):
    holiday = get_holiday(year, month)
    ''' 1日の曜日 '''
    firstweek, lastday = calendar.monthrange(year, month)
    firstweek += 1
    ''' カレンダー生成 '''
    tmp = "{:10d}年{:2d}月     ".format(year, month)
    str = [tmp, "${color2} Su${color7} Mo Tu We Th Fr${color5} Sa${color7}"]
    tmp = ""
    l = 0
    if firstweek != 7:
        tmp = "   " * firstweek
        l = len(tmp)
    for d in range(1, lastday + 1):
        if day and d == day:
            tmp = tmp + "${{color6}}{:3d}${{color7}}".format(d)
            l += 3
        elif (d + firstweek) % 7 == 0:
            tmp = tmp + "${{color5}}{:3d}${{color7}}".format(d)
            l += 3
        elif (d + firstweek) % 7 == 1 or d in holiday:
            tmp = tmp + "${{color2}}{:3d}${{color7}}".format(d)
            l += 3
        else:
            tmp = tmp + "{:3d}".format(d)
            l += 3
        if (d + firstweek) % 7 == 0:
            str.append(tmp)
            tmp = ""
            l = 0
    str.append(tmp + " " * (21 - l))
    if len(str) < 8:
        str.append(" " * 21)
    return str

# 現在の年月
today = datetime.datetime.today()
str1 = make_calendar(today.year, today.month, today.day)
# 翌月
if (today.month == 12):
    # 翌月が来年の場合
    str2 = make_calendar(today.year + 1, 1, 0)
else:
    str2 = make_calendar(today.year, today.month + 1, 0)
for i in range(8):
    print(str1[i] + '  ' + str2[i])

 

Revise this Paste

Your Name: Code Language: