fixes
parent
f7465517e6
commit
f4320efbaa
|
@ -3,6 +3,7 @@ from fetcher.model.feed import db, Registros
|
|||
from tempfile import NamedTemporaryFile
|
||||
from shutil import copyfile
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
import requests
|
||||
import logging
|
||||
import time
|
||||
|
@ -18,7 +19,7 @@ handler.setFormatter(formatter)
|
|||
log.addHandler(handler)
|
||||
|
||||
def load_proto():
|
||||
inicio = datetime.now()
|
||||
inicio = datetime.now(tz=ZoneInfo("America/Santiago"))
|
||||
final_dir = "static/ccp/{}/{}/{}".format(inicio.strftime("%Y"), inicio.strftime("%m"), inicio.strftime("%d"))
|
||||
final_name = "static/ccp/{}/{}/{}/ccp_gtfs_{}.proto".format(inicio.strftime("%Y"), inicio.strftime("%m"), inicio.strftime("%d"), inicio.strftime("%Y%m%d_%H%M_%S"))
|
||||
|
||||
|
@ -32,10 +33,10 @@ def load_proto():
|
|||
nuevo_registro = Registros(filename=final_name, status=0)
|
||||
db.add(nuevo_registro)
|
||||
db.commit()
|
||||
log.info("Fetched GTFS-RT Record {} in {}s".format(inicio.strftime("%Y%m%d_%H%M_%S"), (datetime.now()-inicio).total_seconds()))
|
||||
log.info("Fetched GTFS-RT Record {} in {}s".format(inicio.strftime("%Y%m%d_%H%M_%S"), (datetime.now(tz=ZoneInfo("America/Santiago"))-inicio).total_seconds()))
|
||||
except:
|
||||
import traceback
|
||||
log.error("Failed to fetch GTFS-RT Record {} in {}s".format(inicio.strftime("%Y%m%d_%H%M_%S"), (datetime.now()-inicio).total_seconds()))
|
||||
log.error("Failed to fetch GTFS-RT Record {} in {}s".format(inicio.strftime("%Y%m%d_%H%M_%S"), (datetime.now(tz=ZoneInfo("America/Santiago"))-inicio).total_seconds()))
|
||||
log.info('Traceback {}'.format(traceback.format_exc()))
|
||||
nuevo_registro = Registros(filename=final_name, status=100)
|
||||
db.add(nuevo_registro)
|
||||
|
|
|
@ -41,9 +41,9 @@ def sync_db():
|
|||
if patentedb is None:
|
||||
patentedb = Vehiculo(patente=patente, timestamp=itemts)
|
||||
db.add(patentedb)
|
||||
db.commit()
|
||||
elif patentedb.timestamp < itemts:
|
||||
patentedb.timestamp = itemts
|
||||
db.commit()
|
||||
|
||||
if item.HasField('trip_update'):
|
||||
tripid = item.trip_update.trip.trip_id
|
||||
|
@ -58,9 +58,9 @@ def sync_db():
|
|||
|
||||
tripdb = Viaje(trip_id=tripid, route_id=routeid, direction_id=direccionid, start_time=tstar, start_date=dstart, timestamp=itemts)
|
||||
db.add(tripdb)
|
||||
db.commit()
|
||||
elif tripdb.timestamp < itemts:
|
||||
tripdb.timestamp = itemts
|
||||
db.commit()
|
||||
tripdbid = tripdb.id
|
||||
else:
|
||||
tripdbid = None
|
||||
|
@ -69,9 +69,9 @@ def sync_db():
|
|||
if entidadesdb is None:
|
||||
entidadesdb = Entidades(entity=str(item.id), vehicleid=patentedb.id, tripid=tripdbid, timestamp=itemts)
|
||||
db.add(entidadesdb)
|
||||
db.commit()
|
||||
elif entidadesdb.timestamp < itemts:
|
||||
entidadesdb.timestamp = itemts
|
||||
db.commit()
|
||||
|
||||
posiciondb = db.query(Posicion).filter(Posicion.vehicleid==patentedb.id, Posicion.timestamp==itemts).one_or_none()
|
||||
if posiciondb is None:
|
||||
|
|
Loading…
Reference in New Issue