Use flask config instead of configparser

Closes: #74
This commit is contained in:
Edward Betts 2023-12-07 15:52:48 +00:00
parent 8cf0b982f0
commit 9ff61c3af8
3 changed files with 15 additions and 28 deletions

View file

@ -19,6 +19,7 @@ import agenda.travel
app = flask.Flask(__name__)
app.debug = False
app.config.from_object("config.default")
@app.errorhandler(werkzeug.exceptions.InternalServerError)
@ -52,7 +53,7 @@ def exception_handler(e: werkzeug.exceptions.InternalServerError) -> tuple[str,
async def index() -> str:
"""Index page."""
now = datetime.now()
data = await agenda.data.get_data(now)
data = await agenda.data.get_data(now, app.config)
return flask.render_template("index.html", today=now.date(), **data)
@ -60,8 +61,7 @@ async def index() -> str:
@app.route("/travel")
def travel_list() -> str:
"""Page showing a list of upcoming travel."""
config = agenda.data.get_config()
data_dir = config["data"]["personal-data"]
data_dir = app.config["PERSONAL_DATA"]
flights = agenda.travel.parse_yaml("flights", data_dir)
trains = agenda.travel.parse_yaml("trains", data_dir)
@ -76,8 +76,7 @@ def as_date(d: date | datetime) -> date:
@app.route("/conference")
def conference_list() -> str:
"""Page showing a list of conferences."""
config = agenda.data.get_config()
data_dir = config["data"]["personal-data"]
data_dir = app.config["PERSONAL_DATA"]
filepath = os.path.join(data_dir, "conferences.yaml")
item_list = yaml.safe_load(open(filepath))["conferences"]
today = date.today()