34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
|
from flask import render_template, send_file, Blueprint
|
||
|
from apiweb.model.feed import Registros, Vehiculo, Viaje, Entidades, Posicion
|
||
|
from apiweb.main import db
|
||
|
from time import strftime
|
||
|
import os
|
||
|
|
||
|
|
||
|
main = Blueprint('main', __name__)
|
||
|
|
||
|
@main.route("/gtfs-rt/api")
|
||
|
def home():
|
||
|
records = Registros.query.order_by(Registros.id.desc()).limit(100).all()
|
||
|
return render_template('summary.html', title='Historial', records=records)
|
||
|
|
||
|
|
||
|
@main.route("/gtfs-rt/api/concepcion")
|
||
|
@main.route("/gtfs-rt/api/concepcion/<int:registro_id>")
|
||
|
def concepcion(registro_id=None):
|
||
|
if registro_id is None:
|
||
|
record = Registros.query.order_by(Registros.id.desc()).first()
|
||
|
outfile = "concepcion_gtfs-rt.proto"
|
||
|
else:
|
||
|
record = Registros.query.filter(Registros.id==registro_id).one_or_none()
|
||
|
|
||
|
if record is None:
|
||
|
abort(404)
|
||
|
|
||
|
if id is None:
|
||
|
outfile = "concepcion_gtfs-rt.latest.proto"
|
||
|
else:
|
||
|
outfile = "concepcion_gtfs-rt.{}.proto".format(record.timestamp.strftime("%H%md_%H%M_%S"))
|
||
|
|
||
|
return send_file(os.path.abspath(record.filename), download_name=outfile)
|