Weniger Sicherheitslücken und Fehler
This commit is contained in:
parent
2623dfdf1a
commit
661c703dd7
3 changed files with 114 additions and 63 deletions
53
app.py
53
app.py
|
|
@ -79,6 +79,12 @@ def datei(id):
|
||||||
return audio
|
return audio
|
||||||
|
|
||||||
|
|
||||||
|
def dateiNameFürListe(name):
|
||||||
|
name = name.replace("/", "%2F")
|
||||||
|
name = name + ".json"
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
def kartenGeneriren(song):
|
def kartenGeneriren(song):
|
||||||
id = song["wikiid"]
|
id = song["wikiid"]
|
||||||
print(id)
|
print(id)
|
||||||
|
|
@ -112,6 +118,11 @@ def kartenGeneriren(song):
|
||||||
song["land"] = wikiapi(statements["P495"][0]["value"]["content"], "labels")[
|
song["land"] = wikiapi(statements["P495"][0]["value"]["content"], "labels")[
|
||||||
"de"
|
"de"
|
||||||
]
|
]
|
||||||
|
song["bild"] = (
|
||||||
|
"Flag_of_"
|
||||||
|
+ wikiapi(statements["P495"][0]["value"]["content"], "labels")["en"]
|
||||||
|
+ ".svg"
|
||||||
|
)
|
||||||
if "ytid" not in song and "P1651" in statements:
|
if "ytid" not in song and "P1651" in statements:
|
||||||
song["ytid"] = statements["P1651"][0]["value"]["content"]
|
song["ytid"] = statements["P1651"][0]["value"]["content"]
|
||||||
if "ytid" in song:
|
if "ytid" in song:
|
||||||
|
|
@ -123,6 +134,11 @@ def kartenGeneriren(song):
|
||||||
song["img"] = (
|
song["img"] = (
|
||||||
f"https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/{statements['P18'][0]['value']['content']}&width=300"
|
f"https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/{statements['P18'][0]['value']['content']}&width=300"
|
||||||
)
|
)
|
||||||
|
if "backimg" not in song and "P495" in statements:
|
||||||
|
song["backimg"] = (
|
||||||
|
f"https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/Flag_of_{wikiapi(statements['P495'][0]['value']['content'], 'labels')['en']}.svg&width=300"
|
||||||
|
)
|
||||||
|
print(song["backimg"])
|
||||||
if "img" not in song:
|
if "img" not in song:
|
||||||
song["img"] = (
|
song["img"] = (
|
||||||
"https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/Eurovision_Song_Contest_heart_(2014–2025).svg&width=300"
|
"https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/Eurovision_Song_Contest_heart_(2014–2025).svg&width=300"
|
||||||
|
|
@ -142,9 +158,10 @@ def zeit(sekunden):
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello_world():
|
def hello_world():
|
||||||
liste = request.args.get("liste")
|
liste = request.args.get("liste")
|
||||||
|
flag = request.args.get("flag")
|
||||||
if liste is None:
|
if liste is None:
|
||||||
return redirect("/playlists")
|
return redirect("/playlists")
|
||||||
with open(liste + ".json", "r") as f:
|
with open(dateiNameFürListe(liste), "r") as f:
|
||||||
songs = json.load(f)
|
songs = json.load(f)
|
||||||
for song in songs:
|
for song in songs:
|
||||||
kartenGeneriren(song)
|
kartenGeneriren(song)
|
||||||
|
|
@ -152,7 +169,7 @@ def hello_world():
|
||||||
for song in songs:
|
for song in songs:
|
||||||
gesamtLaenge += song["laenge"]
|
gesamtLaenge += song["laenge"]
|
||||||
return render_template(
|
return render_template(
|
||||||
"index.html", karten=songs, gesamtLaenge=gesamtLaenge, liste=liste
|
"index.html", karten=songs, gesamtLaenge=gesamtLaenge, liste=liste, flag=flag
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -167,7 +184,7 @@ def playlists():
|
||||||
def neueliste():
|
def neueliste():
|
||||||
name = request.args.get("name")
|
name = request.args.get("name")
|
||||||
if name is not None:
|
if name is not None:
|
||||||
with open(name + ".json", "x") as f:
|
with open(dateiNameFürListe(name), "x") as f:
|
||||||
json.dump([], f)
|
json.dump([], f)
|
||||||
return redirect("/?liste=" + name)
|
return redirect("/?liste=" + name)
|
||||||
return render_template("neueliste.html", name=name)
|
return render_template("neueliste.html", name=name)
|
||||||
|
|
@ -189,14 +206,17 @@ def suche():
|
||||||
@app.route("/suche", methods=["POST"])
|
@app.route("/suche", methods=["POST"])
|
||||||
def suche_finden():
|
def suche_finden():
|
||||||
liste = request.args.get("liste")
|
liste = request.args.get("liste")
|
||||||
with open(liste + ".json", "r") as f:
|
if liste:
|
||||||
|
with open(dateiNameFürListe(liste), "r") as f:
|
||||||
songs = json.load(f)
|
songs = json.load(f)
|
||||||
song = {"wikiid": request.form.get("id")}
|
song = {"wikiid": request.form.get("id")}
|
||||||
kartenGeneriren(song)
|
kartenGeneriren(song)
|
||||||
songs.append(song)
|
songs.append(song)
|
||||||
with open(liste + ".json", "w") as f:
|
with open(dateiNameFürListe(liste), "w") as f:
|
||||||
json.dump(songs, f, indent=2, ensure_ascii=False)
|
json.dump(songs, f, indent=2, ensure_ascii=False)
|
||||||
return redirect("/suche?liste=" + liste, 303)
|
return redirect("/suche?liste=" + liste, 303)
|
||||||
|
else:
|
||||||
|
return redirect("/")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/remove")
|
@app.route("/remove")
|
||||||
|
|
@ -204,7 +224,7 @@ def admin():
|
||||||
liste = request.args.get("liste")
|
liste = request.args.get("liste")
|
||||||
if liste is None:
|
if liste is None:
|
||||||
return redirect("/playlists")
|
return redirect("/playlists")
|
||||||
with open(liste + ".json", "r") as f:
|
with open(dateiNameFürListe(liste), "r") as f:
|
||||||
songs = json.load(f)
|
songs = json.load(f)
|
||||||
for song in songs:
|
for song in songs:
|
||||||
kartenGeneriren(song)
|
kartenGeneriren(song)
|
||||||
|
|
@ -219,13 +239,22 @@ def admin():
|
||||||
@app.route("/remove", methods=["POST"])
|
@app.route("/remove", methods=["POST"])
|
||||||
def loeschen():
|
def loeschen():
|
||||||
liste = request.args.get("liste")
|
liste = request.args.get("liste")
|
||||||
song = int(request.form.get("index"))
|
if not liste:
|
||||||
with open(liste + ".json", "r") as f:
|
return "Du Musst eine Liste angeben", 400
|
||||||
print(liste + ".json")
|
song = request.form.get("index")
|
||||||
|
if song is None:
|
||||||
|
return "Kein Lied", 400
|
||||||
|
try:
|
||||||
|
song = int(song)
|
||||||
|
except TypeError:
|
||||||
|
return "Irgendwas ist GANZ falsch", 400
|
||||||
|
try:
|
||||||
|
with open(dateiNameFürListe(liste), "x") as f:
|
||||||
songs = json.load(f)
|
songs = json.load(f)
|
||||||
print(songs)
|
if len(songs) < song + 1:
|
||||||
print(songs)
|
return "Das Lied Gibt es Nicht", 400
|
||||||
del songs[song]
|
del songs[song]
|
||||||
with open(liste + ".json", "w") as f:
|
|
||||||
json.dump(songs, f, indent=2, ensure_ascii=False)
|
json.dump(songs, f, indent=2, ensure_ascii=False)
|
||||||
return redirect("/remove?liste=" + liste, 303)
|
return redirect("/remove?liste=" + liste, 303)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return "Die Liste Ist nicht da (Du kannst Sie anlegen)", 400
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
img {
|
img {
|
||||||
border-radius: 2%;
|
border-radius: 1rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
aspect-ratio: 4/3;
|
aspect-ratio: 4/3;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,27 @@
|
||||||
<article>
|
{% if karte.backimg and flag %}
|
||||||
|
<style>
|
||||||
|
#{{karte.wikiid}} {
|
||||||
|
background-image: url("{{karte.backimg}}");
|
||||||
|
}
|
||||||
|
#inkarte{
|
||||||
|
background-color: white;
|
||||||
|
border-radius: 1rem;
|
||||||
|
filter: drop-shadow(6px 6px 10px black);
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endif %}
|
||||||
|
<article id="{{ karte.wikiid}}">
|
||||||
|
<div id="inkarte">
|
||||||
<img src="{{ karte.img }}" />
|
<img src="{{ karte.img }}" />
|
||||||
{% if karte.ytid %}
|
{% if karte.ytid %}
|
||||||
<p>
|
<p>
|
||||||
<button id="{{karte_loop.index0}}" onclick="vorherige(this.id)">
|
<button id="{{karte_loop.index0}}" onclick="vorherige(this.id)">
|
||||||
Vorherige</button
|
Vorherige</button
|
||||||
><button id="{{karte_loop.index0}}" onclick="abspielendiese(this.id)">
|
><button
|
||||||
|
id="{{karte_loop.index0}}"
|
||||||
|
onclick="abspielendiese(this.id)"
|
||||||
|
>
|
||||||
Abspielen</button
|
Abspielen</button
|
||||||
><button id="{{karte_loop.index0}}" onclick="nächste(this.id)">
|
><button id="{{karte_loop.index0}}" onclick="nächste(this.id)">
|
||||||
Nächstes
|
Nächstes
|
||||||
|
|
@ -28,7 +45,9 @@
|
||||||
<p><b>Länge:</b> {{karte.laenge|zeit}}</p>
|
<p><b>Länge:</b> {{karte.laenge|zeit}}</p>
|
||||||
<p id="gray">
|
<p id="gray">
|
||||||
{% if karte.text %}
|
{% if karte.text %}
|
||||||
<a id="gray" href="{{ karte.text }}" target="_blank">Original Text</a>
|
<a id="gray" href="{{ karte.text }}" target="_blank"
|
||||||
|
>Original Text</a
|
||||||
|
>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a id="gray" href="https://www.wikidata.org/entity/{{karte.wikiid}}"
|
<a id="gray" href="https://www.wikidata.org/entity/{{karte.wikiid}}"
|
||||||
>Q-id:{{karte.wikiid}}</a
|
>Q-id:{{karte.wikiid}}</a
|
||||||
|
|
@ -36,7 +55,10 @@
|
||||||
</p>
|
</p>
|
||||||
{% if admin %}
|
{% if admin %}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<button name="index" value="{{karte_loop.index0}}"><X></button>
|
<button name="index" value="{{karte_loop.index0}}">
|
||||||
|
<X>
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue