Added uebung07
This commit is contained in:
23
cgi-bin/uebung07/doggu.html
Normal file
23
cgi-bin/uebung07/doggu.html
Normal file
File diff suppressed because one or more lines are too long
BIN
cgi-bin/uebung07/knuffig.jpg
Normal file
BIN
cgi-bin/uebung07/knuffig.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 187 KiB |
13
cgi-bin/uebung07/posts-create.py
Normal file
13
cgi-bin/uebung07/posts-create.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import cgi
|
||||||
|
import cgitb
|
||||||
|
cgitb.enable()
|
||||||
|
|
||||||
|
|
||||||
|
form = open("doggu.html", "r").read()
|
||||||
|
print("Content-type: text/html\n")
|
||||||
|
print(form)
|
||||||
|
|
||||||
|
print('<a href="posts-show.py">Zeig mir alle Posts!</a><br>')
|
||||||
|
print('<a href="tags-show.py">Zeig mir alle Tags!</a>')
|
31
cgi-bin/uebung07/posts-show.py
Normal file
31
cgi-bin/uebung07/posts-show.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import cgi
|
||||||
|
import cgitb
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
cgitb.enable()
|
||||||
|
|
||||||
|
|
||||||
|
print("Content-type: text/html\n")
|
||||||
|
print("<head><style>")
|
||||||
|
print("body {background-color: coral;}")
|
||||||
|
print("</style></head>")
|
||||||
|
print("""<h1 style="color:blue;">MEIN TOLLER BLOG</h1>""")
|
||||||
|
file_names= [f for f in os.listdir('posts') if os.path.isfile(os.path.join('posts', f))]
|
||||||
|
file_names = sorted(file_names, reverse=True)
|
||||||
|
for lol in file_names:
|
||||||
|
lol = 'posts/' + lol
|
||||||
|
data = open(lol, "r")
|
||||||
|
data = json.load(data)
|
||||||
|
print('<div style="background-color: palevioletred; border: 5px solid seagreen; border-radius: 10px; padding: 10px;">')
|
||||||
|
print(str(data['title']) + '<br>Datum: ' + str(data['prettytime']))
|
||||||
|
print('<hr>')
|
||||||
|
print(str(data['content']) + '<br><hr>')
|
||||||
|
for lel in data['tags']:
|
||||||
|
print('<a href="tags-show.py?tag=' + str(lel) + '">#' + str(lel) + '</a>')
|
||||||
|
print('</div><br>')
|
||||||
|
|
||||||
|
print()
|
||||||
|
print('<a href="tags-show.py">Zeig mir alle Tags!</a><br>')
|
||||||
|
print('<a href="posts-create.py">Ich will einen neuen Post bauen!</a>')
|
39
cgi-bin/uebung07/posts-store.py
Normal file
39
cgi-bin/uebung07/posts-store.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/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")
|
1
cgi-bin/uebung07/posts/2019-06-14-09-52-08
Normal file
1
cgi-bin/uebung07/posts/2019-06-14-09-52-08
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"tags": ["intech", "sose19", "uni tuebingen"], "published": "2019-06-14-09-52-08", "title": "Intech ist super!", "content": "Inbesondere Python-CGI macht viel Spass!!!"}
|
1
cgi-bin/uebung07/posts/2019-06-14-09-52-39
Normal file
1
cgi-bin/uebung07/posts/2019-06-14-09-52-39
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"title": "PHP ...", "content": "... ist meine Lieblingssprache und in der naechsten Uebung fangen wir damit an!", "published": "2019-06-14-09-52-39", "tags": ["intech", "sose19", "uni tuebingen"]}
|
1
cgi-bin/uebung07/posts/2019-06-14-09-54-27
Normal file
1
cgi-bin/uebung07/posts/2019-06-14-09-54-27
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"tags": ["klausur", "ahhhh!", "intech"], "published": "2019-06-14-09-54-27", "content": "Die Klausur findet am 22. Juli statt. Da ich die Uebungen alle bearbeitet habe, kann nichts schiefgehen!", "title": "Intech-Klausur"}
|
1
cgi-bin/uebung07/posts/2019-06-23-19-16-45
Normal file
1
cgi-bin/uebung07/posts/2019-06-23-19-16-45
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"tags": [" kekse ", " kekese ", " ekskeks"], "published": [2019, 6, 23, 19, 16, 45, 6, 174, 1], "title": "Ih mag kekse", "content": "kesek sindd toll"}
|
52
cgi-bin/uebung07/tags-show.py
Normal file
52
cgi-bin/uebung07/tags-show.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import cgi
|
||||||
|
import cgitb
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
cgitb.enable()
|
||||||
|
|
||||||
|
tag = ""
|
||||||
|
try:
|
||||||
|
form = cgi.FieldStorage(encoding='utf8')
|
||||||
|
tag = form.getvalue('tag')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Zeug zeigen
|
||||||
|
print("Content-type: text/html\n")
|
||||||
|
print("<head><style>")
|
||||||
|
print("body {background-color: coral;}")
|
||||||
|
print("</style></head>")
|
||||||
|
print("""<h1 style="color:blue;">ALLE TAGS</h1>""")
|
||||||
|
file_names= [f for f in os.listdir('posts') if os.path.isfile(os.path.join('posts', f))]
|
||||||
|
tag_set = []
|
||||||
|
if tag:
|
||||||
|
for f in file_names:
|
||||||
|
f = 'posts/' + f
|
||||||
|
data = open(f, "r")
|
||||||
|
data = json.load(data)
|
||||||
|
if tag in data['tags']:
|
||||||
|
print('<div style="background-color: palevioletred; border: 5px solid seagreen; border-radius: 10px; padding: 10px;">')
|
||||||
|
print(str(data['title']) + '<br>Datum: ' + str(data['prettytime']))
|
||||||
|
print('<hr>')
|
||||||
|
print(str(data['content']) + '<br><hr>')
|
||||||
|
for i in data['tags']:
|
||||||
|
print('<a href="tags-show.py?tag=' + str(i) + '">#' + str(i) + '</a>')
|
||||||
|
print('</div><br>')
|
||||||
|
else:
|
||||||
|
print('<div style="background-color: palevioletred; border: 5px solid seagreen; border-radius: 10px; padding: 10px;">')
|
||||||
|
print("Tags<br>")
|
||||||
|
for f in file_names:
|
||||||
|
f = 'posts/' + f
|
||||||
|
data = open(f, "r")
|
||||||
|
tag_set += json.load(data)['tags']
|
||||||
|
for i in sorted(set(tag_set)):
|
||||||
|
print('<a href="tags-show.py?tag=' + str(i) + '">#' + str(i) + '</a><br>')
|
||||||
|
print('</div><br>')
|
||||||
|
|
||||||
|
|
||||||
|
print()
|
||||||
|
print('<a href="posts-show.py">Zeig mir alle Posts!</a><br>')
|
||||||
|
print('<a href="tags-show.py">Falls du noch nicht alle Tags siehst ist dies nach diesem Klick der Fall!</a><br>')
|
||||||
|
print('<a href="posts-create.py">Ich will einen neuen Post bauen!</a>')
|
Reference in New Issue
Block a user