#!/usr/bin/env python2 # -*- coding: utf-8 -*- import code,csv,sys,os,datetime,locale #import dateutil.parser from templates import * import sys sys.path.append("/mnt/web103/c1/41/53451241/htdocs/grav/pythonlib") #TODO check input via regexp? #TODO use style tage instead on inline css #locale.setlocale(locale.LC_ALL, 'de_DE.Utf-8') #locale.setlocale(locale.LC_ALL, 'de_DE.ISO8859-1') html_escape_table = { "&": "&", '"': """, "'": "'", ">": ">", "<": "<", u"ä": "ä", u"ö": "ö", u"ü": "ü", u"Ä": "Ä", u"Ö": "Ö", u"Ü": "Ü", u"ß": "ß", u"„":"“", u"“":"”", } def html_escape(text): """Produce entities within text.""" return u"".join(html_escape_table.get(c,c) for c in text.decode("utf-8")) workdir=os.path.dirname(os.path.realpath(__file__))+"/" #workdir=sys.path[0] #workdir=os.path.dirname(__file__) #workdir=os.path.abspath('') outtype="web"#web,ortsblatt,gembr,kirchenwn logmessage="" #print("hi") #print(workdir) #remove
tags surrounding parameter block of twig filter param=sys.argv[1].replace('
','').replace('
','') #reader=[line.split(";") for line in param.split("\n")] #naive parsing, doesnt support quoted cells reader = csv.reader(param.split('\n'), delimiter=';') #logmessage+="param: {}".format(param) #reader = csv.reader(open(workdir+'termine.csv'), delimiter=';', quotechar='"') #reader = csv.reader(open(workdir+'_termine-csv/text.de.md'), delimiter=';', quotechar='"') reader.next()#skip header #lines=[] table_content="" lastdate=datetime.date(2000,1,1)#date in past -> add heading to first month logmessage+="lastdate is {}\n".format(lastdate) for row in reader: try: if not row:#ignore empty lines continue if not row[0].startswith("20"):#ignore non-date lines (header, comments,...) continue if not len(row)==4: print("error: row has wrong length, malformed csv?") print(row) continue #date=dateutil.parser.parse(row[0]).date() date=datetime.date(*[int(i) for i in row[0].split("-")]) category=row[2] yesterday=datetime.datetime.now().date()-datetime.timedelta(days=1) if date.month>=yesterday.month and date.year>=yesterday.year and outtype in ["web","gembr"]and date.month!=lastdate.month:#add heading style="font-family: Calibri,sans-serif;font-size: 160%;font-weight:bold;text-align:center;" #style="font-size: 18pt;font-weight:bold;" #monthname=html_escape(date.strftime("%B"))+" %i"%date.year monthname=html_escape(monthnames[date.month])+" %i"%date.year #line='