#!/usr/bin/env python # vim: set ts=8 sw=4 sts=4 et ai: # Walter Doekes, 2011 import datetime, locale, logging, os, sys, time try: from cStringIO import StringIO except ImportError: from StringIO import StringIO try: from urlparse import parse_qs except ImportError: from cgi import parse_qs try: from ho import pisa except ImportError, e: raise ImportError('%s\n\n!! Please install python-pisa (the ho.pisa html2pdf converter) !!' % (e,)) DO_PDF = True # Needed to display e.g. font errors. The wanted VAG Round font is # missing a Character to Glyph mapping table (cmap). The reportlab tools # refuse to use the font without it. Next step would be to "fix" the bad # TTF and add the proper cmap (probably constructed from the cp1252 code # page), but that's for another day. class PisaLogHandler(logging.Handler): def emit(self, record): print >>sys.stderr, record.exc_info logging.getLogger("ho.pisa").addHandler(PisaLogHandler()) def generate_weeks(begin_date, weeks, first_day='mon'): first_weekday = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'].index(first_day) curdate = begin_date - datetime.timedelta(days=((7 + begin_date.weekday() - first_weekday) % 7)) curweekno = (curdate + datetime.timedelta(days=4)).isocalendar()[1] # take week# from middle of week weeks_data = [] for i in xrange(weeks): week_days = [] for j in range(7): week_days.append(curdate) curdate += datetime.timedelta(days=1) yield {'num': curweekno, 'days': week_days} curweekno += 1 if curweekno >= 52 and curdate.month == 1: curweekno = 1 def create_calendar_html(title, weeks): style = [] #style.append('@font-face { font-family:"VAG Round";src:url(/usr/share/fonts/truetype/msttcorefonts/vaground.ttf); }') style.append('@font-face { font-family:"Comic Sans MS";src:url(/usr/share/fonts/truetype/msttcorefonts/comic.ttf); }') style.append('table { padding-top:36px;border-collapse:collapse; }') style.append('th,td { font-family:"VAG Round","Comic Sans MS","Comic Sans",sans-serif;font-size:36px; }') style.append('td { padding-top:12px;border-bottom:4px solid black; }') html = [] html.append('\n' '\n' '
#%d | %s |
---|---|
%s | %s |