Zweite version
Playist management
This commit is contained in:
parent
39f95c2857
commit
46e9d5c40d
7 changed files with 70 additions and 14 deletions
53
app.py
Executable file → Normal file
53
app.py
Executable file → Normal file
|
|
@ -47,8 +47,6 @@ def datei(id):
|
|||
|
||||
return audio
|
||||
|
||||
with open("songs.json","r") as f:
|
||||
songs = json.load(f)
|
||||
def kartenGeneriren(song):
|
||||
id = song["wikiid"]
|
||||
statements = wikiapi(id,"statements")
|
||||
|
|
@ -66,7 +64,6 @@ def kartenGeneriren(song):
|
|||
song["interprete"] = " x ".join(set(wikiapi(statement["value"]["content"],"labels")["en"] for statement in statements.get("P175",[])))
|
||||
if "ytid" not in song and "P1651" in statements:
|
||||
song["ytid"] = statements["P1651"][0]["value"]["content"]
|
||||
print(song)
|
||||
if "ytid" in song:
|
||||
song["datei"] = datei(song["ytid"])
|
||||
song["img"] = f"http://img.youtube.com/vi/{ song["ytid"] }/sddefault.jpg"
|
||||
|
|
@ -76,8 +73,7 @@ def kartenGeneriren(song):
|
|||
song["img"] = f"https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/{statements["P18"][0]["value"]["content"]}&width=300"
|
||||
if "img" not in song:
|
||||
song["img"] = "https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/Eurovision_Song_Contest_heart_(2014–2025).svg&width=300"
|
||||
for song in songs:
|
||||
kartenGeneriren(song)
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
@ -90,28 +86,67 @@ def zeit(sekunden):
|
|||
|
||||
@app.route("/")
|
||||
def hello_world():
|
||||
liste = request.args.get("liste")
|
||||
print("/")
|
||||
print(liste)
|
||||
if liste is None:
|
||||
return redirect("/playlists")
|
||||
print(liste)
|
||||
with open(liste+".json","r") as f:
|
||||
songs = json.load(f)
|
||||
for song in songs:
|
||||
kartenGeneriren(song)
|
||||
print(songs)
|
||||
gesamtLaenge = 0
|
||||
for song in songs:
|
||||
gesamtLaenge += song["laenge"]
|
||||
return render_template('index.html', karten=songs,gesamtLaenge=gesamtLaenge )
|
||||
return render_template('index.html', karten=songs,gesamtLaenge=gesamtLaenge,liste=liste )
|
||||
|
||||
|
||||
@app.route("/playlists")
|
||||
def playlists():
|
||||
listen = glob("*.json")
|
||||
listen = (liste.replace(".json","") for liste in listen)
|
||||
print("/playlists")
|
||||
print(listen)
|
||||
return render_template('playlists.html',lists=listen)
|
||||
|
||||
@app.route("/neueliste")
|
||||
def neueliste():
|
||||
name = request.args.get("name")
|
||||
print("/neueliste")
|
||||
print(name)
|
||||
if name is not None:
|
||||
with open(name +".json", "x") as f:
|
||||
json.dump([],f)
|
||||
return redirect("/?liste="+name)
|
||||
print(liste)
|
||||
return render_template('neueliste.html',name=name)
|
||||
|
||||
@app.route("/suche")
|
||||
def suche():
|
||||
such = request.args.get("suche")
|
||||
liste = request.args.get("liste")
|
||||
print("/suche")
|
||||
print(liste)
|
||||
if such is not None:
|
||||
ergebnisse = wikisuche(such)
|
||||
else:
|
||||
ergebnisse = []
|
||||
return render_template('suche.html', ergebnisse=ergebnisse,anfrage=such)
|
||||
return render_template('suche.html', ergebnisse=ergebnisse,anfrage=such,liste=liste)
|
||||
|
||||
@app.route("/suche",methods=["POST"])
|
||||
def suche_finden():
|
||||
liste = request.args.get("liste")
|
||||
with open(liste +".json","r") as f:
|
||||
songs = json.load(f)
|
||||
song = {"wikiid":request.form.get("id")}
|
||||
kartenGeneriren(song)
|
||||
songs.append(song)
|
||||
with open("songs.json","w") as f:
|
||||
print(liste)
|
||||
with open(liste+".json","w") as f:
|
||||
json.dump(songs,f,indent=2,ensure_ascii=False)
|
||||
return redirect("/",303)
|
||||
return redirect("/?liste="+liste,303)
|
||||
|
||||
@app.route("/ADMIN")
|
||||
def admin():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue