Browse Source

Added support for specifying date for train data request

python3
Dan Cojocaru 3 years ago
parent
commit
9a22a8543b
Signed by: kbruen
GPG Key ID: 818A889458EDC937
  1. 9
      server/server/v2/v2.py

9
server/server/v2/v2.py

@ -1,3 +1,4 @@
from datetime import datetime
import json import json
from flask import Blueprint, jsonify, request from flask import Blueprint, jsonify, request
from flask.helpers import url_for from flask.helpers import url_for
@ -41,10 +42,16 @@ def get_train_info_schema():
@bp.route('/train/<train_no>') @bp.route('/train/<train_no>')
def get_train_info(train_no: str): def get_train_info(train_no: str):
use_yesterday = check_yes_no(request.args.get('use_yesterday', ''), default=False) use_yesterday = check_yes_no(request.args.get('use_yesterday', ''), default=False)
date_override = request.args.get('date', default=None)
try:
date_override = datetime.fromisoformat(date_override)
except ValueError:
date_override = None
@filtered_data @filtered_data
def get_data(): def get_data():
from ..scraper.scraper import scrape_train from ..scraper.scraper import scrape_train
result = scrape_train(train_no, use_yesterday=use_yesterday) result = scrape_train(train_no, use_yesterday=use_yesterday, date_override=date_override)
db.on_train_data(result) db.on_train_data(result)
return result return result
if (train_no, use_yesterday) not in train_data_cache: if (train_no, use_yesterday) not in train_data_cache:

Loading…
Cancel
Save