Added uebung07

This commit is contained in:
2019-06-24 10:15:01 +02:00
parent b4acf257f6
commit 2dedd578a4
10 changed files with 162 additions and 0 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

View 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>')

View 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>')

View 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")

View 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!!!"}

View 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"]}

View 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"}

View 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"}

View 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>')