127 lines
3.5 KiB
Python
127 lines
3.5 KiB
Python
|
import sys
|
||
|
import json
|
||
|
import logging
|
||
|
from logging import config
|
||
|
import yaml
|
||
|
from flask import Flask, render_template, redirect, request, url_for
|
||
|
from thsf.backend import Backend
|
||
|
from thsf.schedule import Schedule
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# -- Configuration
|
||
|
# ------------------------------------------------------------------------------
|
||
|
class AppConfig:
|
||
|
""" Flask application config """
|
||
|
CONFIG_FILENAME = "config.yml"
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# -- Application
|
||
|
# ------------------------------------------------------------------------------
|
||
|
logger = logging.getLogger('wsgi')
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# -- Local configuration
|
||
|
# ------------------------------------------------------------------------------
|
||
|
app.config.from_object(__name__ + '.AppConfig')
|
||
|
try:
|
||
|
with open(app.config["CONFIG_FILENAME"], mode="r", encoding="utf-8") as local_config_file:
|
||
|
app.local_config = yaml.load(local_config_file, Loader=yaml.SafeLoader)
|
||
|
app.config["SECRET_KEY"] = app.local_config["app"]["secret_key"]
|
||
|
app.config["LANGUAGES"] = app.local_config["app"]["languages"]
|
||
|
config.dictConfig(app.local_config["log"])
|
||
|
backend = Backend(url=app.local_config["pretalx"]["url"],
|
||
|
apiprefix=app.local_config["pretalx"]["apiprefix"],
|
||
|
apikey=app.local_config["pretalx"]["apikey"])
|
||
|
schedule = Schedule()
|
||
|
except Exception as err:
|
||
|
logger.critical("[{}] {}".format(err.__class__, str(err)))
|
||
|
sys.exit(1)
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# -- Tools
|
||
|
# ------------------------------------------------------------------------------
|
||
|
@app.errorhandler(404)
|
||
|
def page_not_found(err):
|
||
|
return redirect(url_for('index'))
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# -- Routes
|
||
|
# ------------------------------------------------------------------------------
|
||
|
@app.route('/favicon.ico', methods=['GET'])
|
||
|
def favicon():
|
||
|
return redirect(url_for('static', filename='images/favicon.png'))
|
||
|
|
||
|
|
||
|
@app.route('/', methods=['GET'])
|
||
|
def index():
|
||
|
return render_template("index.html")
|
||
|
|
||
|
|
||
|
@app.route('/planning', methods=['GET'])
|
||
|
def planning():
|
||
|
slots = backend.get(endpoint=f"events/{app.local_config['pretalx']['event']}/schedules/{app.local_config['pretalx']['schedule']}").json()
|
||
|
# schedule.set_slots(slots["slots"])
|
||
|
return render_template("planning.html", slots=slots["slots"])
|
||
|
# return "toto"
|
||
|
# for slot in sched["slots"]:
|
||
|
# schedule.add_slot(slot)
|
||
|
# return schedule.df.to_html()
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
@app.route('/concerts', methods=['GET'])
|
||
|
def concerts():
|
||
|
return "concerts"
|
||
|
|
||
|
|
||
|
@app.route('/djsets', methods=['GET'])
|
||
|
def djsets():
|
||
|
return "djsets"
|
||
|
|
||
|
|
||
|
@app.route('/exhibitions', methods=['GET'])
|
||
|
def exhibitions():
|
||
|
return "exhibitions"
|
||
|
|
||
|
|
||
|
@app.route('/lighttalks', methods=['GET'])
|
||
|
def lighttalks():
|
||
|
return "lighttalks"
|
||
|
|
||
|
|
||
|
@app.route('/paneldiscussions', methods=['GET'])
|
||
|
def paneldiscussions():
|
||
|
return "paneldiscussions"
|
||
|
|
||
|
|
||
|
@app.route('/screenings', methods=['GET'])
|
||
|
def screenings():
|
||
|
return "screenings"
|
||
|
|
||
|
|
||
|
@app.route('/talks', methods=['GET'])
|
||
|
def talks():
|
||
|
return "talks"
|
||
|
|
||
|
|
||
|
@app.route('/workshops', methods=['GET'])
|
||
|
def workshops():
|
||
|
return "workshops"
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------------------------------
|
||
|
# -- Main
|
||
|
# ------------------------------------------------------------------------------
|
||
|
if __name__ == '__main__':
|
||
|
app.run(host='127.0.0.1', port=5000, debug=True)
|