Merge pull request 'feat: add ssl_verify parameter' (#5) from ssl/no_verify into master

Reviewed-on: #5
This commit is contained in:
doug713705 2024-11-24 14:43:11 +11:00
commit 5fa1ecf46e
3 changed files with 35 additions and 23 deletions

View File

@ -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

View File

@ -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"])

View File

@ -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)