Files
intecsync/cgi-bin/uebung07/posts-store.py
Janek Schoffit ebba7bc34a chmod
2019-06-24 10:18:57 +02:00

40 lines
1.0 KiB
Python
Executable File

#!/usr/bin/python3
import cgi
import cgitb
import json
from time import strftime, time
cgitb.enable()
param = False
try:
form = cgi.FieldStorage(encoding='utf8')
# nehm die Sachen aus create und bau sie in einen Post :)
title = form.getvalue('title')
content = form.getvalue('content')
tags = form.getvalue('tags')[1:].split("#")
param = True
file_name = "posts/" + strftime("%Y-%m-%d-%H-%M-%S")
nicetime = strftime("%A, %d.%B %Y %H:%M Uhr")
file_content = {
"title": title,
"prettytime": nicetime, #das ist nicht unbedingt sinnvoll, aber mir gefällts.
"content" : content,
"tags" : tags
}
file_content = json.dumps(file_content)
f = open(file_name, "w").write(file_content)
print('Status: 303 See Other')
print('Location: posts-show.py')
print()
except:
print("Content-type: text/html\n")
if not(param):
print("Nothing here. You reached the end of the Internet. Turn back. H.P. Backster. Hyper, Hyper.")
else:
print("Feeehhhleeeerrrr")