summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFlorian <florianraemisch@web.de>2011-10-06 18:04:24 +0200
committerFlorian <florianraemisch@web.de>2011-10-06 18:04:24 +0200
commit0a709221ff584789e29e02ce9207a2e7d585c60e (patch)
tree7ee5f18f6f9804cd04b33c5888eff33f6f217e24 /scripts
parentab825a15a69e3df5f309fbe81bd61611a6c95b65 (diff)
new webscript with new filehierarchy. templates are not up to date!
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/newtemp.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/scripts/newtemp.py b/scripts/newtemp.py
new file mode 100755
index 0000000..d579baf
--- /dev/null
+++ b/scripts/newtemp.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+#Filename: newtemp.py
+#Author: stayawake@lavabit.com
+
+
+import configparser
+import os
+import sys
+import getopt
+import time
+import datetime
+from string import Template
+
+
+def readfiles(prefix):
+
+ global content
+ content= {"content.html":"", "keywords":"", "desc_de":"", "desc_en":""}
+
+ for c in content:
+ f = open(prefix + "." + c, "r")
+ content[c] = f.read()
+ f.close
+
+
+def substitute(target, prefix, htmltemplate, datenow, topic, content):
+
+ #create template-string
+ htmltext = Template(htmltemplate)
+ htmltext = htmltext.substitute(template_date = datenow, template_chattopic = topic, template_keywords = content["keywords"], template_content = content["content.html"], template_desc_de = content["desc_de"], template_desc_en = content["desc_en"])
+
+ #write it to the outputfile
+ outputfile = open(target + page + ".html", "w")
+ outputfile.write(htmltext)
+ outputfile.close()
+
+
+def readarguments(argv):
+
+ global configfile
+ global verbose
+
+ try:
+ opts, args = getopt.getopt(argv, "c:vh", ["config=", "verbose", "help"])
+ except getopt.GetoptError:
+ print("There is a problem with your argument(s)")
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt in ("-c", "--config"):
+ configfile = arg
+ elif opt in ("-v", "--verbose"):
+ verbose = True
+ elif opt in ("-h", "--help"):
+ print("Please read the non-existing man page for further assistance")
+ sys.exit(0)
+
+
+configfile = "template.conf"
+verbose = False
+
+readarguments(sys.argv[1:])
+
+if not(os.path.exists(configfile)):
+ print("Configfile not found")
+ sys.exit(2)
+
+
+config = configparser.ConfigParser()
+config.read_file(open(configfile))
+path = config["Default"]["path"]
+target = config["Default"]["target"]
+pagepath = path + "pages/"
+templatepath = path + "template/"
+topicpath = path + "topic/"
+if verbose:
+ print("Pagepath: %s" % pagepath)
+ print("Templatepath: %s" % templatepath)
+ print("topicpath: %s" % topicpath)
+
+#set template
+f = open(templatepath + "template.html", "r")
+htmltemplate = f.read()
+f.close
+if verbose:
+ print ("template read")
+
+#set topic
+f = open(topicpath + "topic", "r")
+topic = f.read()
+f.close
+if verbose:
+ print ("topic read")
+
+#set date
+datenow = time.strftime("%Y-%m-%dT%H:%M:%S +0100")
+if verbose:
+ print ("Set date: " + datenow)
+
+for page in os.listdir(pagepath):
+ prefix = pagepath + page + "/" + page
+ readfiles(prefix)
+ substitute(target, prefix, htmltemplate, datenow, topic, content)
+ if verbose:
+ print(prefix + ".html written")