theme, plugins und config für die Webseite der Baptisten Hohenacker https://baptisten-hohenacker.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.8 KiB

#!/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 = {
"&": "&",
'"': """,
"'": "'",
">": ">",
"<": "&lt;",
u"ä": "&auml",
u"ö": "&ouml",
u"ü": "&uuml",
u"Ä": "&Auml",
u"Ö": "&Ouml",
u"Ü": "&Uuml",
u"ß": "&szlig;",
}
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 <p> </p> tags surrounding parameter block of twig filter
param=sys.argv[1].replace('<p>','').replace('</p>','')
#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 {}".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 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='<tr style="%s"><td></td><td></td><td colspan="2">%s</td></tr>'%(style,monthname)
#line=html_line_template.format(date="",time=monthname,text="",weekday="",style=style,padding=5)
if outtype is "web":
line='<tr style="%s"><td colspan="4" style="padding-right: 120px;">%s</td></tr>'%(style,monthname)
elif outtype is "gembr":
line=gembr_html_line_template.format(date="",time="<font size='5'><b>%s</b></font>"%monthname,text="",weekday="")
table_content+=line+"\n"
if outtype=="kirchenwn" and category in ["godi","text_fett"]:
weekday=weekday_names[date.weekday()]
datestr=" %02i.%02i.%04i"%(date.day,date.month,date.year)
text=web_templates[category].format(param=row[3])
line=html_line_template.format(date=datestr,time=row[1],text=html_escape(text),weekday=weekday,padding=5,style="")
table_content+=line+"\n"
if outtype in ["web","gembr"] and date>yesterday:
if date!=lastdate:
weekday=weekday_names_short[date.weekday()]
datestr=" %02i.%02i."%(date.day,date.month)
else:
weekday=""
datestr=""
text=web_templates[category].format(param=row[3])
#if outtype=="ortsblatt":
#style+="font-family: 'Times New Roman', serif;"
if outtype is "web":
style="font-family: Calibri,sans-serif;"
if category in ["godi","text_fett"]:
style+="font-size: 100%;text-decoration: underline;font-weight:bold;"
else:
style+="font-size: 100%;"#font-size: 14pt;
time="&nbsp;".join(row[1].split(" "))#make space in "10.00 Uhr" non breaking
line=html_line_template.format(date=datestr,time=time,text=html_escape(text),weekday=weekday,style=style,padding=5)
elif outtype is "gembr":
if category in ["godi","text_fett"]:
line=gembr_html_line_template_bold_ul.format(date=datestr,time=row[1],text=html_escape(text),weekday=weekday)
else:
line=gembr_html_line_template.format(date=datestr,time=row[1],text=html_escape(text),weekday=weekday)
table_content+=line+"\n"
lastdate=date
except:
print "error at row:"
print row
pass
logmessage+="generated sucessfully"
table_html=html_template.format(table_content=table_content)
table_html+="""<script>console.log("{}")</script>""".format(logmessage)
#f = open("table.html",'w')
#f.writelines(table_html)
#f.close()
print(table_html)