Skip to content

Instantly share code, notes, and snippets.

@tschloss
Created August 12, 2013 00:03
Show Gist options
  • Save tschloss/6207461 to your computer and use it in GitHub Desktop.
Save tschloss/6207461 to your computer and use it in GitHub Desktop.
Python script that prints a 3-month calendar (previous, current, next month) WITH calendar weeks. The current day is highlighted. No parameters currently. INTENDED USE: Geeklet for Geek-Tool.
import calendar
import datetime
import time
now = time.localtime()
curj=now[0] if now[1]>1 else now[0]-1 #2013
curm=now[1]-1 if now[1]>1 else 12 #8
for i in range(3,0,-1):
kw=datetime.date(curj, curm, 1).isocalendar()[1]
print calendar.month_name[curm],curj,"\nWK|",calendar.weekheader(2)
m = calendar.monthcalendar(curj,curm)
for l in m:
line = '{:2d}|'.format(kw)
for d in l:
if d==now[2] and curm==now[1]:
line += '\033[1;31m'
line = line + (' {:2d}'.format(d) if (d>0) else ' ')
if d==now[2] and curm==now[1]:
line += '\033[0m'
print line
kw+=1
if curm<12:
curm += 1
else:
curm = 1
curj += 1
if i>1:
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment