1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/usr/bin/python
import string
import time
import datetime
from string import Template
def readfiles(prefix):
#set globals
global content
global keywords
global desc_de
global desc_en
#set content
f = open(prefix + ".content.html", "r")
content = f.read()
f.close
#set keywords
f = open(prefix + ".keywords", "r")
keywords = f.read()
f.close
#set german description
f = open(prefix + ".desc_de", "r")
desc_de = f.read()
f.close
#set english description
f = open(prefix + ".desc_en", "r")
desc_en = f.read()
f.close
def substitute(target, prefix, htmltemplate, datenow, chattopic, keywords, content, desc_de, desc_en):
#create template-string
htmltext = Template(htmltemplate)
htmltext = htmltext.substitute(template_date = datenow, template_chattopic = chattopic, template_keywords = keywords, template_content = content, template_desc_de = desc_de, template_desc_en = desc_en)
#write it to the outpufile
outputfile = open(target + prefix + ".html", "w")
outputfile.write(htmltext)
outputfile.close()
contentpath = "../template/"
target = "../public/"
#set template
f = open(contentpath + "template.html", "r")
htmltemplate = f.read()
f.close
print ("template read")
#set chattopic
f = open(contentpath + "chattopic", "r")
chattopic = f.read()
f.close
print ("chattopic read")
#set date
datenow = time.strftime("%Y-%m-%dT%H:%M:%S +0100")
print ("Set date: " + datenow)
prefixes = ['index', 'neues', 'termine', 'raeume', 'lage', 'kontakt', 'verein', 'impressum', 'webcam']
for prefix in prefixes:
readfiles(contentpath + prefix)
substitute(target, prefix, htmltemplate, datenow, chattopic, keywords, content, desc_de, desc_en)
print(prefix + ".html written")
|