Various improvements
This commit is contained in:
parent
876eb6a759
commit
1fa2e68b31
5 changed files with 101 additions and 8 deletions
37
app.py
37
app.py
|
|
@ -31,12 +31,28 @@ def index():
|
|||
return render_template('index.html', destinations=DESTINATIONS, today=today)
|
||||
|
||||
|
||||
VALID_MIN_CONNECTIONS = {50, 60, 70, 80, 90, 100, 110, 120}
|
||||
VALID_MAX_CONNECTIONS = {60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180}
|
||||
|
||||
|
||||
@app.route('/search')
|
||||
def search():
|
||||
slug = request.args.get('destination', '')
|
||||
travel_date = request.args.get('travel_date', '')
|
||||
try:
|
||||
min_conn = int(request.args.get('min_connection', 50))
|
||||
except ValueError:
|
||||
min_conn = 50
|
||||
if min_conn not in VALID_MIN_CONNECTIONS:
|
||||
min_conn = 50
|
||||
try:
|
||||
max_conn = int(request.args.get('max_connection', 110))
|
||||
except ValueError:
|
||||
max_conn = 110
|
||||
if max_conn not in VALID_MAX_CONNECTIONS:
|
||||
max_conn = 110
|
||||
if slug in DESTINATIONS and travel_date:
|
||||
return redirect(url_for('results', slug=slug, travel_date=travel_date))
|
||||
return redirect(url_for('results', slug=slug, travel_date=travel_date, min_connection=min_conn, max_connection=max_conn))
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
||||
|
|
@ -46,6 +62,19 @@ def results(slug, travel_date):
|
|||
if not destination or not travel_date:
|
||||
return redirect(url_for('index'))
|
||||
|
||||
try:
|
||||
min_connection = int(request.args.get('min_connection', 50))
|
||||
except ValueError:
|
||||
min_connection = 50
|
||||
if min_connection not in VALID_MIN_CONNECTIONS:
|
||||
min_connection = 50
|
||||
try:
|
||||
max_connection = int(request.args.get('max_connection', 110))
|
||||
except ValueError:
|
||||
max_connection = 110
|
||||
if max_connection not in VALID_MAX_CONNECTIONS:
|
||||
max_connection = 110
|
||||
|
||||
user_agent = request.headers.get('User-Agent', rtt_scraper.DEFAULT_UA)
|
||||
|
||||
rtt_cache_key = f"rtt_{travel_date}"
|
||||
|
|
@ -78,7 +107,7 @@ def results(slug, travel_date):
|
|||
msg = f"Could not fetch Eurostar times: {e}"
|
||||
error = f"{error}; {msg}" if error else msg
|
||||
|
||||
trips = combine_trips(gwr_trains, eurostar_trains, travel_date)
|
||||
trips = combine_trips(gwr_trains, eurostar_trains, travel_date, min_connection, max_connection)
|
||||
|
||||
dt = date.fromisoformat(travel_date)
|
||||
prev_date = (dt - timedelta(days=1)).isoformat()
|
||||
|
|
@ -103,6 +132,10 @@ def results(slug, travel_date):
|
|||
error=error,
|
||||
eurostar_url=eurostar_url,
|
||||
rtt_url=rtt_url,
|
||||
min_connection=min_connection,
|
||||
max_connection=max_connection,
|
||||
valid_min_connections=sorted(VALID_MIN_CONNECTIONS),
|
||||
valid_max_connections=sorted(VALID_MAX_CONNECTIONS),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue