Skip to content

Instantly share code, notes, and snippets.

@chesster
Created February 17, 2014 03:07
Show Gist options
  • Save chesster/9044005 to your computer and use it in GitHub Desktop.
Save chesster/9044005 to your computer and use it in GitHub Desktop.
Two month conky calendar
#!/usr/bin/env python
import time, calendar, re
def display_cals():
localtime = time.localtime(time.time())
weeks = cal(localtime[0], localtime[1], localtime[2], 10)
cal(localtime[0], localtime[1]+1, 0, 190, int('-%s' % (16*weeks)))
def cal(year, month, day=0, offset=0, voffset=0):
calendar.setfirstweekday(calendar.SUNDAY)
cal = calendar.month(year, month)
parts = cal.split('\n')
offset = '${offset %s}' % offset
weeks = len(parts)-1
cal = offset+('\n'+offset).join(parts)
regex = '(?<= )%s(?= )|(?<=\n)%s(?= )|(?<= )%s(?=\n)' % (day, day, day)
replace = '${color1}%s${color2}' % day
newCal = re.sub(regex, replace, cal)
print "${color0}${voffset %s}%s${color0}" % (voffset, newCal)
return weeks
display_cals()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment