From 3dab312a745e771666002fd3a1551f982c7253bc Mon Sep 17 00:00:00 2001 From: mco-system Date: Sun, 24 Nov 2024 14:42:20 +1100 Subject: [PATCH] feat: add ssl_verify parameter --- config.yml | 3 ++- src/thsf/__init__.py | 45 +++++++++++++++++++++--------------- src/thsf/backend/__init__.py | 10 +++++--- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/config.yml b/config.yml index 5fa4724..dd5e86b 100644 --- a/config.yml +++ b/config.yml @@ -23,7 +23,8 @@ app: name: THSF real_url: https://www.thsf.net pretalx: - url: https://23.thsf.net + url: https://thsf.tetaneutral.net + ssl_verify: False apiprefix: api apikey: bb770a53b15467dfb67c03d178004aca9e4819d6 event: thsf-2023 diff --git a/src/thsf/__init__.py b/src/thsf/__init__.py index c8e5714..83760a8 100644 --- a/src/thsf/__init__.py +++ b/src/thsf/__init__.py @@ -1,10 +1,8 @@ -import re import sys -import json import logging from logging import config import yaml -from flask import Flask, render_template, redirect, request, url_for +from flask import Flask, render_template, redirect, url_for from flask_minify import minify from thsf.backend import Backend from thsf.schedule import Schedule @@ -37,7 +35,8 @@ try: 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"]) + apikey=app.local_config["pretalx"]["apikey"], + ssl_verify=app.local_config["pretalx"]["ssl_verify"]) schedule = Schedule() navbar = Navbar(config=app.local_config["navbar"]) except Exception as err: @@ -47,6 +46,7 @@ except Exception as err: if app.local_config["log"]["root"]["level"] != "DEBUG": minify(app=app, html=True, js=True, cssless=True) + # ------------------------------------------------------------------------------ # -- Tools # ------------------------------------------------------------------------------ @@ -63,7 +63,7 @@ def get_speaker_biography(code): try: speaker_info = backend.get(endpoint=f"events/{app.local_config['pretalx']['event']}/speakers/{code}/").json() return speaker_info.get("biography").strip() - except Exception as err: + except Exception: return None @@ -125,9 +125,10 @@ def planning(): for slot in slots.get("slots"): for speaker in slot.get("speakers"): speaker["biography"] = get_speaker_biography(speaker.get("code")) + slots = sorted(slots.get("slots"), + key=lambda slot: slot.get("slot").get("start")) return render_template("planning.html", - slots=sorted(slots.get("slots"), - key=lambda slot: slot.get("slot").get("start")), + slots=slots, navbar=navbar.get_from_page(page="/planning"), filter=["concert", "dj set", "panel discussion", "talk", "screening"]) @@ -153,9 +154,10 @@ def goodies(): @app.route('/concerts', methods=['GET']) def concerts(): slots = get_slots() + slots = sorted(slots.get("slots"), + key=lambda slot: slot.get("slot").get("start")) return render_template("planning.html", - slots=sorted(slots.get("slots"), - key=lambda slot: slot.get("slot").get("start")), + slots=slots, navbar=navbar.get_from_page(page="/concerts"), filter=["concert", "dj set"]) @@ -163,9 +165,10 @@ def concerts(): @app.route('/workshops', methods=['GET']) def workshops(): slots = get_slots() + slots = sorted(slots.get("slots"), + key=lambda slot: slot.get("slot").get("start")) return render_template("planning.html", - slots=sorted(slots.get("slots"), - key=lambda slot: slot.get("slot").get("start")), + slots=slots, navbar=navbar.get_from_page(page="/workshops"), filter=["workshop"]) @@ -173,9 +176,10 @@ def workshops(): @app.route('/screenings', methods=['GET']) def screenings(): slots = get_slots() + slots = sorted(slots.get("slots"), + key=lambda slot: slot.get("slot").get("start")) return render_template("planning.html", - slots=sorted(slots.get("slots"), - key=lambda slot: slot.get("slot").get("start")), + slots=slots, navbar=navbar.get_from_page(page="/screenings"), filter=["screening"]) @@ -183,9 +187,10 @@ def screenings(): @app.route('/discussions', methods=['GET']) def discussions(): slots = get_slots() + slots = sorted(slots.get("slots"), + key=lambda slot: slot.get("slot").get("start")) return render_template("planning.html", - slots=sorted(slots.get("slots"), - key=lambda slot: slot.get("slot").get("start")), + slots=slots, navbar=navbar.get_from_page(page="/discussions"), filter=["panel discussion"]) @@ -193,9 +198,10 @@ def discussions(): @app.route('/exhibitions', methods=['GET']) def exhibitions(): slots = get_slots() + slots = sorted(slots.get("slots"), + key=lambda slot: slot.get("slot").get("start")) return render_template("planning.html", - slots=sorted(slots.get("slots"), - key=lambda slot: slot.get("slot").get("start")), + slots=slots, navbar=navbar.get_from_page(page="/exhibitions"), filter=["installation"]) @@ -203,9 +209,10 @@ def exhibitions(): @app.route('/talks', methods=['GET']) def talks(): slots = get_slots() + slots = sorted(slots.get("slots"), + key=lambda slot: slot.get("slot").get("start")) return render_template("planning.html", - slots=sorted(slots.get("slots"), - key=lambda slot: slot.get("slot").get("start")), + slots=slots, navbar=navbar.get_from_page(page="/talks"), filter=["talk", "light talk"]) diff --git a/src/thsf/backend/__init__.py b/src/thsf/backend/__init__.py index 1eb615d..7bc7d56 100644 --- a/src/thsf/backend/__init__.py +++ b/src/thsf/backend/__init__.py @@ -1,15 +1,19 @@ import requests -import logging + class Backend: - def __init__(self, url, apiprefix, apikey): + def __init__(self, url, apiprefix, apikey, ssl_verify): self.url = url self.apiprefix = apiprefix self.apikey = apikey + self.ssl_verify = ssl_verify self.session = requests.Session() def get(self, endpoint, params=None): url = f"{self.url}/{self.apiprefix}/{endpoint}" headers = {"Authorization": f"Token {self.apikey}", "Accept": "application/json"} - return self.session.get(url, params=params, headers=headers) + return self.session.get(url, + params=params, + headers=headers, + verify=self.ssl_verify)