cambios sabado 2 de marzo 2024

master
Francisco Sandoval 2024-03-02 18:10:51 -03:00
parent 4c27c97e6d
commit 7273f21e5a
1 changed files with 34 additions and 4 deletions

38
main.py
View File

@ -13,7 +13,6 @@ r = redis.Redis(host=db_host, port=db_port, decode_responses=True)
def main():
print(datetime.now(tz))
# print("hola")
fileproto = download_file_proto()
if fileproto == None:
@ -21,11 +20,14 @@ def main():
namefile = r.get('fileproto')
if namefile == fileproto['name']:
print(namefile)
print(namefile, flush=True)
return
# eliminar toda la informacion actual
r.flushdb()
r.set('fileproto', fileproto['name'])
print(fileproto['name'])
print(fileproto['name'], flush=True)
data = read_file_proto_x_stop(fileproto['content'])
# save data to redis db
@ -81,7 +83,35 @@ def read_file_proto_x_stop(content):
trip_data["arrival_time"] = update.arrival.time
trip_data["hora_llegada"] = datetime.fromtimestamp(update.arrival.time).strftime('%H:%M:%S')
key = f'stop_id:{update.stop_id}'
stop_id = '--'
if update.stop_id != None and update.stop_id > '':
stop_id = update.stop_id
key = f'stop_id:{stop_id}'
if key in data_stop:
data_stop[key].append(trip_data)
else:
data_stop[key] = [ trip_data ]
else:
key = f'stop_id:none'
trip_data = {
"id": str(entity.id),
"trip_id": entity.vehicle.trip.trip_id,
"route_id":entity.vehicle.trip.route_id,
"direction_id": entity.vehicle.trip.direction_id,
"start_time": entity.vehicle.trip.start_time,
"start_date": entity.vehicle.trip.start_date,
"schedule_relationship": entity.vehicle.trip.schedule_relationship,
"vehicle_license_plate": entity.vehicle.vehicle.license_plate,
"latitude": entity.vehicle.position.latitude,
"longitude": entity.vehicle.position.longitude,
"bearing": entity.vehicle.position.bearing,
"odometer": entity.vehicle.position.odometer,
"speed": entity.vehicle.position.speed
}
if key in data_stop:
data_stop[key].append(trip_data)
else: