mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-05-19 11:01:47 +02:00
Add config
This commit is contained in:
parent
2e65679c06
commit
c62314d9eb
4
config.json
Normal file
4
config.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"password": "w",
|
||||
"username": "admin"
|
||||
}
|
21
helpers.py
21
helpers.py
@ -1,5 +1,9 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import json
|
||||
import os
|
||||
|
||||
config_file = "config.json"
|
||||
|
||||
def get_catalog_url():
|
||||
r = requests.get('https://www.karafun.de/karaoke-song-list.html')
|
||||
@ -10,3 +14,20 @@ def get_catalog_url():
|
||||
def get_songs(url):
|
||||
r = requests.get(url)
|
||||
return r.text
|
||||
|
||||
def check_config_exists():
|
||||
return os.path.isfile(config_file)
|
||||
|
||||
def setup_config(app):
|
||||
if check_config_exists():
|
||||
config = json.load(open(config_file))
|
||||
with open(config_file, 'r') as handle:
|
||||
config = json.load(handle)
|
||||
print("Loaded existing config")
|
||||
else:
|
||||
config = {'username': 'admin', 'password': 'Karaoke2019blubb'}
|
||||
with open(config_file, 'w') as handle:
|
||||
json.dump(config, handle, indent=4, sort_keys=True)
|
||||
print("Wrote new config")
|
||||
app.config['BASIC_AUTH_USERNAME'] = config['username']
|
||||
app.config['BASIC_AUTH_PASSWORD'] = config['password']
|
||||
|
11
main.py
11
main.py
@ -6,9 +6,6 @@ import json
|
||||
from flask_basicauth import BasicAuth
|
||||
app = Flask(__name__, static_url_path='/static')
|
||||
|
||||
app.config['BASIC_AUTH_USERNAME'] = 'admin'
|
||||
app.config['BASIC_AUTH_PASSWORD'] = 'Karaoke2019blubb'
|
||||
|
||||
basic_auth = BasicAuth(app)
|
||||
|
||||
@app.route("/")
|
||||
@ -38,10 +35,12 @@ def songs():
|
||||
return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
|
||||
|
||||
@app.route("/api/songs/update")
|
||||
@basic_auth.required
|
||||
def update_songs():
|
||||
database.delete_all_entries()
|
||||
database.import_songs(helpers.get_songs(helpers.get_catalog_url()))
|
||||
return Response('{"status":"OK"}', mimetype='text/json')
|
||||
status = database.import_songs(helpers.get_songs(helpers.get_catalog_url()))
|
||||
print(status)
|
||||
return Response('{"status": "%s" }' % status, mimetype='text/json')
|
||||
|
||||
|
||||
@app.route("/api/songs/compl")
|
||||
@ -82,6 +81,8 @@ def activate_job():
|
||||
database.create_entry_table()
|
||||
database.create_song_table()
|
||||
database.create_list_view()
|
||||
helpers.setup_config(app)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, host='0.0.0.0')
|
||||
|
Loading…
x
Reference in New Issue
Block a user