From 7f155dc09e2b8862d68ee40d514de16c064bf449 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sat, 4 Jan 2025 02:46:47 +0100 Subject: Get prototype working --- halfnarp2.py | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'halfnarp2.py') diff --git a/halfnarp2.py b/halfnarp2.py index 8d736a0..827055a 100755 --- a/halfnarp2.py +++ b/halfnarp2.py @@ -9,11 +9,12 @@ import requests import json import uuid import markdown +from datetime import datetime, time, timedelta from html_sanitizer import Sanitizer from hashlib import sha256 -db = SQLAlchemy(app) app = Flask(__name__) +db = SQLAlchemy() class TalkPreference(db.Model): @@ -118,21 +119,18 @@ def get_preferences(public_uid): def filter_keys_halfnarp(session): - abstract_html = markdown.markdown(submission["abstract"], enable_attributes=False) + abstract_html = markdown.markdown(session["abstract"], enable_attributes=False) abstract_clean_html = Sanitizer().sanitize(abstract_html) - slot = submission["slot"] + slot = session["slot"] return { - "title": submission.get("title", "!!! NO TITLE !!!"), - "duration": 60 * submission.get("duration", 40), - "event_id": submission["code"], - "language": submission.get("content_locale", "de"), - "track_id": submission["track_id"], + "title": session.get("title", "!!! NO TITLE !!!"), + "duration": 60 * session.get("duration", 40), + "event_id": session["code"], + "language": session.get("content_locale", "de"), + "track_id": session["track_id"], "speaker_names": ", ".join( - [ - speaker.get("name", "unnamed") - for speaker in submission.get("speakers", {}) - ] + [speaker.get("name", "unnamed") for speaker in session.get("speakers", {})] ), "abstract": abstract_clean_html, "room_id": slot.get("room_id", "room_unknown"), @@ -143,13 +141,13 @@ def filter_keys_halfnarp(session): def filter_keys_fullnarp(session, speakers): abstract_html = markdown.markdown(session["abstract"], enable_attributes=False) abstract_clean_html = Sanitizer().sanitize(abstract_html) - slot = submission["slot"] + slot = session["slot"] speaker_info = [] - for speaker in submission.get("speakers", {}): + for speaker in session.get("speakers", {}): speaker_info.append(speakers[speaker["code"]]) # if len(speakers[speaker['code']]['availabilities']) == 0: - # print ( "Track " + str(submission['track_id']) + ": Speaker " + speaker.get('name', 'unname') + " on session: " + session.get('title', '!!! NO TITLE !!!') + " without availability. https://cfp.cccv.de/orga/event/38c3/submissions/" + session['code'] ) + # print ( "Track " + str(submission['track_id']) + ": Speaker " + speaker.get('name', 'unname') + " on session: " + session.get('title', '!!! NO TITLE !!!') + " without availability. https://cfp.cccv.de/orga/event/38c3/session/" + session['code'] ) """This fixes availabilites ranging to or from exactly midnight to the more likely start of availibility at 8am and end of availibility at 3am""" @@ -179,19 +177,17 @@ def filter_keys_fullnarp(session, speakers): avail["end"] = str(end_new) return { - "title": submission.get("title", "!!! NO TITLE !!!"), - "duration": 60 * submission.get("duration", 40), - "event_id": submission["code"], - "language": submission.get("content_locale", "de"), - "track_id": submission["track_id"], + "title": session.get("title", "!!! NO TITLE !!!"), + "duration": 60 * session.get("duration", 40), + "event_id": session["code"], + "language": session.get("content_locale", "de"), + "track_id": session["track_id"], + "speakers": speaker_info, "speaker_names": ", ".join( - [ - speaker.get("name", "unnamed") - for speaker in submission.get("speakers", {}) - ] + [speaker.get("name", "unnamed") for speaker in session.get("speakers", {})] ), "abstract": abstract_clean_html, - "room_id": slot.get("room_id", "room_unknown"), + "room_id": "room" + str(slot.get("room_id", "_unknown")), "start_time": slot.get("start", "1970-01-01"), } @@ -217,7 +213,7 @@ def fetch_talks(config): speakers = dict((speaker["code"], speaker) for speaker in speakers_json["results"]) sessions = [ - filter_keys(submission) + filter_keys_halfnarp(submission) for submission in talks_json["results"] if submission["state"] == "confirmed" and not "non-public" in submission.get("tags", {}) @@ -278,7 +274,7 @@ if __name__ == "__main__": app.jinja_env.lstrip_blocks = True CORS() - db.init(app) + db.init_app(app) with app.app_context(): db.create_all() -- cgit v1.2.3