diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2025-01-04 02:46:47 +0100 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2025-01-04 02:46:47 +0100 |
| commit | 7f155dc09e2b8862d68ee40d514de16c064bf449 (patch) | |
| tree | 23c8967b2257c8c7748cd60c34ebad9e302793e0 /halfnarp2.py | |
| parent | ab32e563be8d99010245fc546817c5a2526d7b09 (diff) | |
Get prototype working
Diffstat (limited to 'halfnarp2.py')
| -rwxr-xr-x | halfnarp2.py | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/halfnarp2.py b/halfnarp2.py index 8d736a0..827055a 100755 --- a/halfnarp2.py +++ b/halfnarp2.py | |||
| @@ -9,11 +9,12 @@ import requests | |||
| 9 | import json | 9 | import json |
| 10 | import uuid | 10 | import uuid |
| 11 | import markdown | 11 | import markdown |
| 12 | from datetime import datetime, time, timedelta | ||
| 12 | from html_sanitizer import Sanitizer | 13 | from html_sanitizer import Sanitizer |
| 13 | from hashlib import sha256 | 14 | from hashlib import sha256 |
| 14 | 15 | ||
| 15 | db = SQLAlchemy(app) | ||
| 16 | app = Flask(__name__) | 16 | app = Flask(__name__) |
| 17 | db = SQLAlchemy() | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | class TalkPreference(db.Model): | 20 | class TalkPreference(db.Model): |
| @@ -118,21 +119,18 @@ def get_preferences(public_uid): | |||
| 118 | 119 | ||
| 119 | 120 | ||
| 120 | def filter_keys_halfnarp(session): | 121 | def filter_keys_halfnarp(session): |
| 121 | abstract_html = markdown.markdown(submission["abstract"], enable_attributes=False) | 122 | abstract_html = markdown.markdown(session["abstract"], enable_attributes=False) |
| 122 | abstract_clean_html = Sanitizer().sanitize(abstract_html) | 123 | abstract_clean_html = Sanitizer().sanitize(abstract_html) |
| 123 | slot = submission["slot"] | 124 | slot = session["slot"] |
| 124 | 125 | ||
| 125 | return { | 126 | return { |
| 126 | "title": submission.get("title", "!!! NO TITLE !!!"), | 127 | "title": session.get("title", "!!! NO TITLE !!!"), |
| 127 | "duration": 60 * submission.get("duration", 40), | 128 | "duration": 60 * session.get("duration", 40), |
| 128 | "event_id": submission["code"], | 129 | "event_id": session["code"], |
| 129 | "language": submission.get("content_locale", "de"), | 130 | "language": session.get("content_locale", "de"), |
| 130 | "track_id": submission["track_id"], | 131 | "track_id": session["track_id"], |
| 131 | "speaker_names": ", ".join( | 132 | "speaker_names": ", ".join( |
| 132 | [ | 133 | [speaker.get("name", "unnamed") for speaker in session.get("speakers", {})] |
| 133 | speaker.get("name", "unnamed") | ||
| 134 | for speaker in submission.get("speakers", {}) | ||
| 135 | ] | ||
| 136 | ), | 134 | ), |
| 137 | "abstract": abstract_clean_html, | 135 | "abstract": abstract_clean_html, |
| 138 | "room_id": slot.get("room_id", "room_unknown"), | 136 | "room_id": slot.get("room_id", "room_unknown"), |
| @@ -143,13 +141,13 @@ def filter_keys_halfnarp(session): | |||
| 143 | def filter_keys_fullnarp(session, speakers): | 141 | def filter_keys_fullnarp(session, speakers): |
| 144 | abstract_html = markdown.markdown(session["abstract"], enable_attributes=False) | 142 | abstract_html = markdown.markdown(session["abstract"], enable_attributes=False) |
| 145 | abstract_clean_html = Sanitizer().sanitize(abstract_html) | 143 | abstract_clean_html = Sanitizer().sanitize(abstract_html) |
| 146 | slot = submission["slot"] | 144 | slot = session["slot"] |
| 147 | 145 | ||
| 148 | speaker_info = [] | 146 | speaker_info = [] |
| 149 | for speaker in submission.get("speakers", {}): | 147 | for speaker in session.get("speakers", {}): |
| 150 | speaker_info.append(speakers[speaker["code"]]) | 148 | speaker_info.append(speakers[speaker["code"]]) |
| 151 | # if len(speakers[speaker['code']]['availabilities']) == 0: | 149 | # if len(speakers[speaker['code']]['availabilities']) == 0: |
| 152 | # 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'] ) | 150 | # 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'] ) |
| 153 | 151 | ||
| 154 | """This fixes availabilites ranging to or from exactly midnight to the more likely start of availibility at 8am and end of availibility at 3am""" | 152 | """This fixes availabilites ranging to or from exactly midnight to the more likely start of availibility at 8am and end of availibility at 3am""" |
| 155 | 153 | ||
| @@ -179,19 +177,17 @@ def filter_keys_fullnarp(session, speakers): | |||
| 179 | avail["end"] = str(end_new) | 177 | avail["end"] = str(end_new) |
| 180 | 178 | ||
| 181 | return { | 179 | return { |
| 182 | "title": submission.get("title", "!!! NO TITLE !!!"), | 180 | "title": session.get("title", "!!! NO TITLE !!!"), |
| 183 | "duration": 60 * submission.get("duration", 40), | 181 | "duration": 60 * session.get("duration", 40), |
| 184 | "event_id": submission["code"], | 182 | "event_id": session["code"], |
| 185 | "language": submission.get("content_locale", "de"), | 183 | "language": session.get("content_locale", "de"), |
| 186 | "track_id": submission["track_id"], | 184 | "track_id": session["track_id"], |
| 185 | "speakers": speaker_info, | ||
| 187 | "speaker_names": ", ".join( | 186 | "speaker_names": ", ".join( |
| 188 | [ | 187 | [speaker.get("name", "unnamed") for speaker in session.get("speakers", {})] |
| 189 | speaker.get("name", "unnamed") | ||
| 190 | for speaker in submission.get("speakers", {}) | ||
| 191 | ] | ||
| 192 | ), | 188 | ), |
| 193 | "abstract": abstract_clean_html, | 189 | "abstract": abstract_clean_html, |
| 194 | "room_id": slot.get("room_id", "room_unknown"), | 190 | "room_id": "room" + str(slot.get("room_id", "_unknown")), |
| 195 | "start_time": slot.get("start", "1970-01-01"), | 191 | "start_time": slot.get("start", "1970-01-01"), |
| 196 | } | 192 | } |
| 197 | 193 | ||
| @@ -217,7 +213,7 @@ def fetch_talks(config): | |||
| 217 | speakers = dict((speaker["code"], speaker) for speaker in speakers_json["results"]) | 213 | speakers = dict((speaker["code"], speaker) for speaker in speakers_json["results"]) |
| 218 | 214 | ||
| 219 | sessions = [ | 215 | sessions = [ |
| 220 | filter_keys(submission) | 216 | filter_keys_halfnarp(submission) |
| 221 | for submission in talks_json["results"] | 217 | for submission in talks_json["results"] |
| 222 | if submission["state"] == "confirmed" | 218 | if submission["state"] == "confirmed" |
| 223 | and not "non-public" in submission.get("tags", {}) | 219 | and not "non-public" in submission.get("tags", {}) |
| @@ -278,7 +274,7 @@ if __name__ == "__main__": | |||
| 278 | app.jinja_env.lstrip_blocks = True | 274 | app.jinja_env.lstrip_blocks = True |
| 279 | CORS() | 275 | CORS() |
| 280 | 276 | ||
| 281 | db.init(app) | 277 | db.init_app(app) |
| 282 | 278 | ||
| 283 | with app.app_context(): | 279 | with app.app_context(): |
| 284 | db.create_all() | 280 | db.create_all() |
