mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-05-19 11:01:47 +02:00
Initial Commit
This commit is contained in:
commit
645fe3a8a5
71
.vscode/launch.json
vendored
Normal file
71
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{"name":"Python: Flask","type":"python","request":"launch","module":"flask","env":{"FLASK_APP":"main.py","FLASK_ENV":"development","FLASK_DEBUG":"1"},"args":["run","--no-debugger","--no-reload"],"jinja":true},
|
||||||
|
{
|
||||||
|
"name": "Python: Current File (Integrated Terminal)",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${file}",
|
||||||
|
"console": "integratedTerminal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Python: Remote Attach",
|
||||||
|
"type": "python",
|
||||||
|
"request": "attach",
|
||||||
|
"port": 5678,
|
||||||
|
"host": "localhost",
|
||||||
|
"pathMappings": [
|
||||||
|
{
|
||||||
|
"localRoot": "${workspaceFolder}",
|
||||||
|
"remoteRoot": "."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Python: Module",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"module": "enter-your-module-name-here",
|
||||||
|
"console": "integratedTerminal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Python: Django",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/manage.py",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"args": [
|
||||||
|
"runserver",
|
||||||
|
"--noreload",
|
||||||
|
"--nothreading"
|
||||||
|
],
|
||||||
|
"django": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Python: Flask",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"module": "flask",
|
||||||
|
"env": {
|
||||||
|
"FLASK_APP": "app.py"
|
||||||
|
},
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"--no-debugger",
|
||||||
|
"--no-reload"
|
||||||
|
],
|
||||||
|
"jinja": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Python: Current File (External Terminal)",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${file}",
|
||||||
|
"console": "externalTerminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "/usr/bin/python"
|
||||||
|
}
|
39
database.py
Normal file
39
database.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import sqlite3
|
||||||
|
import pandas
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
song_table = "songs"
|
||||||
|
entry_table = "entries"
|
||||||
|
index_label = "Id"
|
||||||
|
|
||||||
|
def open_db():
|
||||||
|
conn = sqlite3.connect("test.db")
|
||||||
|
return conn
|
||||||
|
|
||||||
|
def import_songs(song_csv):
|
||||||
|
df = pandas.read_csv(StringIO(song_csv), sep=';')
|
||||||
|
conn = open_db()
|
||||||
|
df.to_sql(song_table, conn, if_exists='replace',
|
||||||
|
index=False)
|
||||||
|
conn.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
def create_entry_table():
|
||||||
|
conn = open_db()
|
||||||
|
t = (entry_table,)
|
||||||
|
conn.execute('CREATE TABLE IF NOT EXISTS '+entry_table +
|
||||||
|
' (ID INTEGER PRIMARY KEY NOT NULL, Song_Id INTEGER NOT NULL, Name VARCHAR(255))')
|
||||||
|
|
||||||
|
def create_list_view():
|
||||||
|
conn = open_db()
|
||||||
|
conn.execute("""CREATE VIEW IF NOT EXISTS [Liste] AS
|
||||||
|
SELECT Name, Title, Artist
|
||||||
|
FROM entries, songs
|
||||||
|
WHERE entries.Song_Id=songs.Id""")
|
||||||
|
|
||||||
|
def get_list():
|
||||||
|
conn = open_db()
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute("SELECT * FROM Liste")
|
||||||
|
return cur.fetchall()
|
||||||
|
|
16
helpers.py
Normal file
16
helpers.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
def get_catalog_url():
|
||||||
|
r = requests.get('https://www.karafun.de/karaoke-song-list.html')
|
||||||
|
soup = BeautifulSoup(r.content, 'html.parser')
|
||||||
|
url = soup.findAll('a', href=True, text='CSV')[0]['href']
|
||||||
|
return url
|
||||||
|
|
||||||
|
def get_songs(url):
|
||||||
|
r = requests.get(url)
|
||||||
|
return r.text
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(get_songs)
|
27
main.py
Normal file
27
main.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from flask import Flask, render_template
|
||||||
|
import helpers
|
||||||
|
import database
|
||||||
|
import os, errno
|
||||||
|
app = Flask(__name__)
|
||||||
|
@app.route("/")
|
||||||
|
def home():
|
||||||
|
return render_template('index.html', list=database.get_list())
|
||||||
|
|
||||||
|
@app.route("/list")
|
||||||
|
def index():
|
||||||
|
list = database.get_list()
|
||||||
|
for entry in list:
|
||||||
|
print(entry[0])
|
||||||
|
return str(database.get_list())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
"""try:
|
||||||
|
os.remove("test.db")
|
||||||
|
print("removed database")
|
||||||
|
except OSError:
|
||||||
|
print("failed to remove database")
|
||||||
|
pass"""
|
||||||
|
database.create_entry_table()
|
||||||
|
database.create_list_view()
|
||||||
|
database.import_songs(helpers.get_songs(helpers.get_catalog_url()))
|
||||||
|
app.run(debug=True)
|
30
templates/index.html
Normal file
30
templates/index.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Hello!</h1>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">Song</th>
|
||||||
|
<th scope="col">Künstler</th>
|
||||||
|
</tr>
|
||||||
|
{% for entry in list: %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ entry[0] }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ entry[1] }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ entry[2] }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user