Add config system with TFL_DATA_DIR and CACHE_DIR

config/default.py holds defaults using ~/lib/data/tfl (expanduser, so safe
to commit). app.py loads it then overlays config/local.py if present, pushing
paths into cache and circle_line modules. config/local.py is gitignored for
machine-specific absolute paths (e.g. on the server where www-data runs).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2026-04-04 13:37:44 +01:00
parent c215456620
commit cd37f0619b
6 changed files with 24 additions and 3 deletions

12
app.py
View file

@ -3,6 +3,7 @@ Combine GWR Bristol→Paddington trains with Eurostar St Pancras→destination t
"""
from flask import Flask, render_template, redirect, url_for, request
from datetime import date, timedelta
import os
from cache import get_cached, set_cached
import scraper.eurostar as eurostar_scraper
@ -22,7 +23,16 @@ RTT_BRISTOL_URL = (
"?stp=WVS&show=pax-calls&order=wtt"
)
app = Flask(__name__)
app = Flask(__name__, instance_relative_config=False)
app.config.from_object('config.default')
_local = os.path.join(os.path.dirname(__file__), 'config', 'local.py')
if os.path.exists(_local):
app.config.from_pyfile(_local)
import cache
import circle_line
cache.CACHE_DIR = app.config['CACHE_DIR']
circle_line._TXC_XML = app.config['CIRCLE_LINE_XML']
DESTINATIONS = {
'paris': 'Paris Gare du Nord',