mirror of https://gitlab.com/m3f_usm/proto
cambios sabado 2 de marzo 2024
parent
4c27c97e6d
commit
7273f21e5a
38
main.py
38
main.py
|
@ -13,7 +13,6 @@ r = redis.Redis(host=db_host, port=db_port, decode_responses=True)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(datetime.now(tz))
|
print(datetime.now(tz))
|
||||||
# print("hola")
|
|
||||||
|
|
||||||
fileproto = download_file_proto()
|
fileproto = download_file_proto()
|
||||||
if fileproto == None:
|
if fileproto == None:
|
||||||
|
@ -21,11 +20,14 @@ def main():
|
||||||
|
|
||||||
namefile = r.get('fileproto')
|
namefile = r.get('fileproto')
|
||||||
if namefile == fileproto['name']:
|
if namefile == fileproto['name']:
|
||||||
print(namefile)
|
print(namefile, flush=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# eliminar toda la informacion actual
|
||||||
|
r.flushdb()
|
||||||
|
|
||||||
r.set('fileproto', fileproto['name'])
|
r.set('fileproto', fileproto['name'])
|
||||||
print(fileproto['name'])
|
print(fileproto['name'], flush=True)
|
||||||
data = read_file_proto_x_stop(fileproto['content'])
|
data = read_file_proto_x_stop(fileproto['content'])
|
||||||
|
|
||||||
# save data to redis db
|
# save data to redis db
|
||||||
|
@ -81,11 +83,39 @@ def read_file_proto_x_stop(content):
|
||||||
trip_data["arrival_time"] = update.arrival.time
|
trip_data["arrival_time"] = update.arrival.time
|
||||||
trip_data["hora_llegada"] = datetime.fromtimestamp(update.arrival.time).strftime('%H:%M:%S')
|
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:
|
if key in data_stop:
|
||||||
data_stop[key].append(trip_data)
|
data_stop[key].append(trip_data)
|
||||||
else:
|
else:
|
||||||
data_stop[key] = [ trip_data ]
|
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:
|
||||||
|
data_stop[key] = [ trip_data ]
|
||||||
|
|
||||||
# data_dict = trip_data.copy()
|
# data_dict = trip_data.copy()
|
||||||
# data_dict["stop_sequence"] = update.stop_sequence
|
# data_dict["stop_sequence"] = update.stop_sequence
|
||||||
|
|
Loading…
Reference in New Issue