wip: backend

This commit is contained in:
Michael Costa 2023-04-08 14:17:49 +11:00
parent 8a9df4871f
commit a93e39d984
7 changed files with 54 additions and 30 deletions

View File

@ -24,7 +24,8 @@ app:
real_url: https://www.thsf.net real_url: https://www.thsf.net
pretalx: pretalx:
url: https://23.thsf.net url: https://23.thsf.net
apikey: sdfsdfsdf apiprefix: api
apikey: bb770a53b15467dfb67c03d178004aca9e4819d6
event: thsf-2023 event: thsf-2023
schedule: wip schedule: wip

View File

@ -3,3 +3,4 @@ wheel
flask flask
gunicorn gunicorn
pyYAML pyYAML
requests

View File

@ -22,6 +22,7 @@ install_requires =
flask flask
gunicorn gunicorn
pyYAML pyYAML
request
[options.packages.find] [options.packages.find]
where = src where = src

View File

@ -3,6 +3,7 @@ import logging
from logging import config from logging import config
import yaml import yaml
from flask import Flask, render_template, redirect, request, url_for from flask import Flask, render_template, redirect, request, url_for
from thsf.backend import Backend
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -30,6 +31,9 @@ try:
app.config["SECRET_KEY"] = app.local_config["app"]["secret_key"] app.config["SECRET_KEY"] = app.local_config["app"]["secret_key"]
app.config["LANGUAGES"] = app.local_config["app"]["languages"] app.config["LANGUAGES"] = app.local_config["app"]["languages"]
config.dictConfig(app.local_config["log"]) 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"])
except Exception as err: except Exception as err:
logger.critical("[{}] {}".format(err.__class__, str(err))) logger.critical("[{}] {}".format(err.__class__, str(err)))
sys.exit(1) sys.exit(1)
@ -56,6 +60,7 @@ def index():
@app.route('/planning', methods=['GET']) @app.route('/planning', methods=['GET'])
def planning(): def planning():
backend.get(endpoint=f"events/{app.local_config['pretalx']['event']}/schedules/{app.local_config['pretalx']['schedule']}")
return "planning" return "planning"
@app.route('/concerts', methods=['GET']) @app.route('/concerts', methods=['GET'])

View File

@ -0,0 +1,15 @@
import requests
class Backend(url, apiprefix, apikey):
def __init__(self, url, apiprefix, apikey):
self.url = url
self.apiprefix = apiprefix
self.apikey = apikey
self.session = requests.Session()
def get(self, endpoint, params=None):
url = f"{self.url}/{self.apiprefix}/{endpoint}"
headers = {f"Authorization: Token {self.apikey}"}
return self.session.get(url, **{"params": params, "headers": headers})

View File

@ -23,7 +23,8 @@
<div id="navbar_wrapper"> <div id="navbar_wrapper">
<i class="button tooltip black fa-regular fa-calendar" <i class="button tooltip black fa-regular fa-calendar"
title="Programme" title="Programme"
alt="Programme"> alt="Programme"
onclick="document.location='/planning'">
<span class="tooltiptext thin">Programme</span> <span class="tooltiptext thin">Programme</span>
</i> </i>
<i class="button tooltip black fa-solid fa-map-location-dot" <i class="button tooltip black fa-solid fa-map-location-dot"