diff --git a/GenPoster/app.py b/GenPoster/app.py index 4196139..a09548f 100644 --- a/GenPoster/app.py +++ b/GenPoster/app.py @@ -25,22 +25,6 @@ def reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto): def aprox(n): return int(np.round(n)) -def load_data(): - data = { - "direction": "R", - "distance": 1948.575483806973, - "epochTime": 1674650956, - "latitude": -33.43729782104492, - "licensePlate": "LJHA57", - "longitude": -70.52730560302734, - "realtime": True, - "route": "401", - "routeId": "401", - "timeLabel": "09:49", - "tripId": "401-I-L-005" - } - return data - def approx_km(data): distance_meters = data["distance"] distance_km = distance_meters / 100 # Convert meters to kilometers @@ -97,8 +81,8 @@ def main(): print(data) # Calcula el tiempo restante a la llegada - remaining_time1 = calc_remaining_time(data1) - remaining_time2 = calc_remaining_time(data2) + remaining_time1 = data1['timeRemaining'] + remaining_time2 = data2['timeRemaining'] # Obtiene valores máximos y mínimo de rangos para desplegar en pantalla min_time1, max_time1 = obtain_min_max_time(remaining_time1) min_time2, max_time2 = obtain_min_max_time(remaining_time2) diff --git a/GenPoster/getData.py b/GenPoster/getData.py index 29d9c83..4dd6e43 100644 --- a/GenPoster/getData.py +++ b/GenPoster/getData.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import requests +import pytz from datetime import datetime, timedelta @@ -62,7 +63,8 @@ class Paradero: def __generate_bus_list(self, info): data_main = [] - hora_actual = datetime.now().time() + zona_horaria_santiago = pytz.timezone('America/Santiago') + hora_actual_santiago = datetime.now(zona_horaria_santiago).time() for i in range(len(info["GetInfoDeviceResponse"]["DetalleLineas"])): @@ -76,13 +78,23 @@ class Paradero: bus_info["number_background_color"] = data["colorFondo"] bus_info["letter_background_color"] = data["colorTexto"] bus_info["patente"] = data["Llegadas"][0]["patente"] - diff = timedelta(hours = datetime.strptime(bus_info["timeLabel"], "%H:%M:%S").time().hour - hora_actual.hour,minutes = datetime.strptime(bus_info["timeLabel"], "%H:%M:%S").time().minute - hora_actual.minute,seconds=datetime.strptime(bus_info["timeLabel"], "%H:%M:%S").time().second - hora_actual.second) + bus_hour = datetime.strptime(bus_info["timeLabel"], "%H:%M:%S").time().hour if datetime.strptime(bus_info["timeLabel"], "%H:%M:%S").time().hour != 0 else 24 + print(bus_hour, hora_actual_santiago.hour) + diff = timedelta( + hours = bus_hour - hora_actual_santiago.hour, + minutes = datetime.strptime(bus_info["timeLabel"], "%H:%M:%S").time().minute - hora_actual_santiago.minute, + seconds=datetime.strptime(bus_info["timeLabel"], "%H:%M:%S").time().second - hora_actual_santiago.second + ) + print(diff.total_seconds()) bus_info["timeRemaining"] = int(abs(diff.total_seconds() // 60)) data_main.append(bus_info) data_main = sorted(data_main, key=lambda x: x['timeRemaining']) self.bus_list = data_main + for d in data_main: + print(d['timeRemaining'], d['timeLabel']) + def __serialize_data(self, response): data = response.json() self.__generate_bus_list(data) diff --git a/GenPoster/requirements.txt b/GenPoster/requirements.txt index 135105f..79d1590 100644 --- a/GenPoster/requirements.txt +++ b/GenPoster/requirements.txt @@ -1,4 +1,5 @@ matplotlib requests Pillow -numpy \ No newline at end of file +numpy +pytz \ No newline at end of file diff --git a/GenPoster/scripts/Poster/TimeAnnouncement.py b/GenPoster/scripts/Poster/TimeAnnouncement.py index 6106358..709fc4a 100644 --- a/GenPoster/scripts/Poster/TimeAnnouncement.py +++ b/GenPoster/scripts/Poster/TimeAnnouncement.py @@ -52,7 +52,8 @@ class TimeAnnouncement(MyDraw): if (int(max_time) <= 1): text = "< 1 min" elif (int(min_time) >= 10): - text = "> 10 min" + print(max_time) + text = f"> {max_time} min" else: text = f'{min_time} a {max_time} min'