diff --git a/backend/.vscode/launch.json b/backend/.vscode/launch.json new file mode 100644 index 0000000..9475a54 --- /dev/null +++ b/backend/.vscode/launch.json @@ -0,0 +1,25 @@ +{ + // 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": "app/main.py", + "FLASK_ENV": "development", + "FLASK_DEBUG": "0" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "jinja": true + } + ] +} \ No newline at end of file diff --git a/backend/.vscode/settings.json b/backend/.vscode/settings.json new file mode 100644 index 0000000..e36cb65 --- /dev/null +++ b/backend/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/usr/bin/python3.8" +} \ No newline at end of file diff --git a/backend/app/database.py b/backend/app/database.py index 96b1c9a..903c831 100644 --- a/backend/app/database.py +++ b/backend/app/database.py @@ -9,6 +9,13 @@ entry_table = "entries" index_label = "Id" done_table = "done_songs" + +def dict_factory(cursor, row): + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + return d + def open_db(): conn = sqlite3.connect("data/test.db") conn.execute('PRAGMA encoding = "UTF-8";') @@ -94,12 +101,13 @@ def get_song_list(): def get_song_completions(input_string): conn = open_db() + conn.row_factory = dict_factory cur = conn.cursor() # Don't look, it burns... prepared_string = "%{0}%".format(input_string).upper() # "Test" -> "%TEST%" print(prepared_string) cur.execute( - "SELECT Title || \" - \" || Artist AS Song, Id FROM songs WHERE REPLACE(REPLACE(REPLACE(REPLACE(UPPER( SONG ),'ö','Ö'),'ü','Ü'),'ä','Ä'),'ß','ẞ') LIKE (?) LIMIT 20;", (prepared_string,)) + "SELECT * FROM songs WHERE REPLACE(REPLACE(REPLACE(REPLACE(UPPER( Title ),'ö','Ö'),'ü','Ü'),'ä','Ä'),'ß','ẞ') LIKE (?) LIMIT 20;", (prepared_string,)) return cur.fetchall() def add_entry(name,song_id): diff --git a/backend/app/main.py b/backend/app/main.py index e163ee4..c0d4ed1 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,4 +1,5 @@ from flask import Flask, render_template, Response, abort, request, redirect +from flask_cors import CORS import helpers import database import data_adapters @@ -7,6 +8,7 @@ import json from flask_basicauth import BasicAuth app = Flask(__name__, static_url_path='/static') +CORS(app) basic_auth = BasicAuth(app) accept_entries = False @@ -65,7 +67,8 @@ def get_song_completions(input_string=""): if input_string!="": print(input_string) list = database.get_song_completions(input_string=input_string) - return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json') + return Response(json.dumps(list).encode('utf-8'), mimetype='application/json') +# return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json') else: return 400