diff --git a/main.py b/main.py index 5d8fe98..a6d49ae 100644 --- a/main.py +++ b/main.py @@ -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,11 +83,39 @@ 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: + data_stop[key] = [ trip_data ] # data_dict = trip_data.copy() # data_dict["stop_sequence"] = update.stop_sequence