From 5be7db4fe2184e35b7d8046c5a92308f280800d7 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 23 Dec 2024 00:11:08 +0100 Subject: Defer db configuration until main --- rater.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/rater.py b/rater.py index 8fb3233..1ebc422 100755 --- a/rater.py +++ b/rater.py @@ -11,25 +11,8 @@ import json # import urllib3.contrib.pyopenssl # urllib3.contrib.pyopenssl.inject_into_urllib3() -parser = ArgumentParser(description="C3 rating helper") -parser.add_argument("-i", action="store_true", dest="pretalx_import", default=False, help="import events from pretalx") -parser.add_argument("-c", "--config", help="Config file location", default="./config.json") -args = parser.parse_args() - -with open(args.config, mode="r", encoding="utf-8") as json_file: - config = json.load(json_file) - +db = SQLAlchemy() app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + config['pretalx-conference'] + '-' + config['track'] + '.db' -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -app.config['SECRET_KEY'] = 'Silence is golden. Gerd Eist.' -app.jinja_env.trim_blocks = True -app.jinja_env.lstrip_blocks = True - -db = SQLAlchemy(app) - -config['pretalx-conf-url'] = config['pretalx-url'] + 'orga/event/' + config['pretalx-conference'] -config['pretalx-api-url'] = config['pretalx-url'] + 'api/events/' + config['pretalx-conference'] + '/submissions?track_id' + str(config['track-id']) class Event(db.Model): """An event as dumped from pretalx""" @@ -157,6 +140,25 @@ def fetch_talks(): if __name__ == "__main__": + + parser = ArgumentParser(description="C3 rating helper") + parser.add_argument("-i", action="store_true", dest="pretalx_import", default=False, help="import events from pretalx") + parser.add_argument("-c", "--config", help="Config file location", default="./config.json") + args = parser.parse_args() + + with open(args.config, mode="r", encoding="utf-8") as json_file: + config = json.load(json_file) + config['pretalx-conf-url'] = config['pretalx-url'] + 'orga/event/' + config['pretalx-conference'] + config['pretalx-api-url'] = config['pretalx-url'] + 'api/events/' + config['pretalx-conference'] + '/submissions?track_id' + str(config['track-id']) + + app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + config['pretalx-conference'] + '-' + config['track'] + '.db' + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + app.config['SECRET_KEY'] = 'Silence is golden. Gerd Eist.' + app.jinja_env.trim_blocks = True + app.jinja_env.lstrip_blocks = True + + db.init_app(app) + with app.app_context(): db.create_all() if args.pretalx_import: -- cgit v1.2.3