forked from TDTP/pantallas-led
Add files via upload
parent
0d9f958762
commit
8d77225bee
Binary file not shown.
Binary file not shown.
|
@ -3,6 +3,7 @@ from scripts.Poster.BusPoster import BusPoster
|
|||
from scripts.Poster.TimeAnnouncement import TimeAnnouncement
|
||||
import numpy as np
|
||||
from datetime import datetime, timedelta
|
||||
from import_data import export_data
|
||||
from PIL import Image
|
||||
|
||||
def reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto):
|
||||
|
@ -47,7 +48,7 @@ def approx_km(data):
|
|||
return approx_km
|
||||
|
||||
def calc_remaining_time(data):
|
||||
arrival_time = data["timeLabel"]
|
||||
arrival_time = data["timeLabel"][:-3]
|
||||
target_time = datetime.strptime(arrival_time, "%H:%M").time()
|
||||
current_time = datetime.now().time()
|
||||
|
||||
|
@ -87,18 +88,25 @@ def obtain_min_max_time(remaining_time):
|
|||
|
||||
def main():
|
||||
# Carga los datos
|
||||
data = load_data()
|
||||
#data = load_data()
|
||||
data = export_data()
|
||||
data1 = data[0]
|
||||
data2 = data[1]
|
||||
|
||||
print(data)
|
||||
|
||||
# Calcula el tiempo restante a la llegada
|
||||
remaining_time = calc_remaining_time(data)
|
||||
remaining_time1 = calc_remaining_time(data1)
|
||||
remaining_time2 = calc_remaining_time(data2)
|
||||
# Obtiene valores máximos y mínimo de rangos para desplegar en pantalla
|
||||
min_time, max_time = obtain_min_max_time(remaining_time)
|
||||
min_time1, max_time1 = obtain_min_max_time(remaining_time1)
|
||||
min_time2, max_time2 = obtain_min_max_time(remaining_time2)
|
||||
|
||||
# Selecciona el tema
|
||||
theme = 'day'
|
||||
theme = 'night'
|
||||
|
||||
# Alto y ancho de la imagen en pixeles
|
||||
# height, width = 40, 160
|
||||
#height, width = 40, 160
|
||||
height, width = 200, 800
|
||||
|
||||
# Inicia el dibujo y setea el tema
|
||||
|
@ -112,7 +120,7 @@ def main():
|
|||
time_anmc1.start_draw()
|
||||
# time_anmc1.set_background()
|
||||
# time_anmc1.set_base_text()
|
||||
time_anmc1.set_min_max_text(min_time=min_time, max_time=max_time)
|
||||
time_anmc1.set_min_max_text(min_time=min_time1, max_time=max_time1)
|
||||
|
||||
# Agrega el anuncio de los minutos restante al arribo
|
||||
time_anmc2 = TimeAnnouncement(aprox((2/5)*height), aprox((1/3)*width))
|
||||
|
@ -120,8 +128,8 @@ def main():
|
|||
time_anmc2.start_draw()
|
||||
# time_anmc2.set_background()
|
||||
# time_anmc2.set_base_text()
|
||||
time_anmc2.set_min_max_text(min_time=3, max_time=5)
|
||||
|
||||
time_anmc2.set_min_max_text(min_time=min_time2, max_time=max_time2)
|
||||
|
||||
# Genera la imagen de la linea del bus
|
||||
poster1 = BusPoster(aprox(1.1*(1/3)*height), aprox(1.1*(1/3)*width))
|
||||
poster1.set_theme(theme)
|
||||
|
@ -140,9 +148,10 @@ def main():
|
|||
poster1.set_params(bus_announcement_1)
|
||||
poster1.load_barlow()
|
||||
poster1.set_colors()
|
||||
|
||||
# Se setea la ruta y la direccion en la que va
|
||||
poster1.set_bus_number(bus_number=data["route"])
|
||||
poster1.set_bus_letter(bus_letter=data["direction"])
|
||||
poster1.set_bus_number(bus_number=data1["route"])
|
||||
poster1.set_bus_letter(bus_letter=data1["direction"])
|
||||
|
||||
# Genera la imagen de la linea del bus
|
||||
poster2 = BusPoster(aprox(1.1*(1/3)*height), aprox(1.1*(1/3)*width))
|
||||
|
@ -163,27 +172,24 @@ def main():
|
|||
poster2.load_barlow()
|
||||
poster2.set_colors()
|
||||
# Se setea la ruta y la direccion en la que va
|
||||
poster2.set_bus_number(bus_number="16")
|
||||
poster2.set_bus_letter(bus_letter="H")
|
||||
poster2.set_bus_number(bus_number=data2["route"])
|
||||
poster2.set_bus_letter(bus_letter=data2["direction"])
|
||||
|
||||
# Se agregan todas las imagenes al canvas
|
||||
full_panel.add_image(time_anmc1, (aprox((0.6)*width), aprox(0.05*height)))
|
||||
full_panel.add_image(time_anmc2, (aprox((0.6)*width), aprox(0.45*height)))
|
||||
full_panel.add_image(poster1, (aprox((0.05)*width), aprox((0.1)*height)))
|
||||
full_panel.add_image(poster2, (aprox((0.05)*width), aprox((0.5)*height)))
|
||||
# full_panel.add_image(bm, (aprox(0.02*width),aprox((1/6)*height)))
|
||||
#full_panel.add_image(bm, (aprox(0.02*width),aprox((1/6)*height)))
|
||||
full_panel.get_image()
|
||||
input_path = f'/app/example/poster_{height}_{width}.png'
|
||||
full_panel.save_image(input_path)
|
||||
# Ejemplo de uso:
|
||||
full_panel.save_image('/app/example/poster.png')
|
||||
|
||||
nuevo_alto = 40 # Reemplaza con el alto deseado en píxeles
|
||||
nuevo_ancho = 160 # Reemplaza con el ancho deseado en píxeles
|
||||
|
||||
input_path = f'/app/example/poster.png'
|
||||
output_path = f'/app/example/poster_{nuevo_alto}_{nuevo_ancho}.png'
|
||||
|
||||
reescalar_imagen(input_path, output_path, nuevo_ancho, nuevo_alto)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 944 B After Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.0 KiB |
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def api_request():
|
||||
# URL de la API para "autentificación"
|
||||
url_auth = 'https://transporte.hz.kursor.cl/api/auth/'
|
||||
|
||||
# Datos para autentificar
|
||||
auth = '''{
|
||||
"username": "usuario1",
|
||||
"password": "usuario1"
|
||||
}'''
|
||||
|
||||
# Request
|
||||
token = requests.post(url_auth, data=auth)
|
||||
token = token.json()['token']
|
||||
|
||||
# URL de la API para info del paradero
|
||||
url_whoami = 'https://transporte.hz.kursor.cl/api/dispositivos/whoami/'
|
||||
|
||||
# Datos de la solicitud
|
||||
data_whoami = {
|
||||
"whoami": {
|
||||
"idDispositivo": "pled30-gtr",
|
||||
"KeyAuthorizacion": "token"
|
||||
}
|
||||
}
|
||||
|
||||
#Aquí se ingresa el token obtenido anteriormente
|
||||
headers_whoami = {
|
||||
'Authorization': f'Bearer {token}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response_whoami = requests.post(url_whoami, json=data_whoami, headers=headers_whoami) #Request
|
||||
Paradero = response_whoami.json()
|
||||
|
||||
url_getinfodevice = 'https://transporte.hz.kursor.cl/api/dispositivos/getInfoDevice/' # URL de la API para obtener los datos de los recorridos
|
||||
|
||||
# Datos para la solicitud
|
||||
data_getinfodevice = {
|
||||
"GetInfoDevice": {
|
||||
"idDispositivo": "00000000160f3b42b8:27:eb:0f:3b:42",
|
||||
"KeyAuthorizacion": "tokenSinUso"
|
||||
}
|
||||
}
|
||||
|
||||
#Aquí se ingresa el token obtenido anteriormente
|
||||
headers_getinfodevice = {
|
||||
'Authorization': f'Bearer {token}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
# Request
|
||||
response_getinfodevice = requests.post(url_getinfodevice, json=data_getinfodevice, headers=headers_getinfodevice)
|
||||
info = response_getinfodevice.json()
|
||||
|
||||
return info
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#Haciendo una lista de todos los buses de este paradero
|
||||
|
||||
def lista_buses(info):
|
||||
data_main = []
|
||||
hora_actual = datetime.now().time()
|
||||
|
||||
for i in range(len(info["GetInfoDeviceResponse"]["DetalleLineas"])):
|
||||
|
||||
data = info["GetInfoDeviceResponse"]["DetalleLineas"][i]
|
||||
|
||||
bus_info = {}
|
||||
bus_info["distance"] = data["Llegadas"][0]["DistanciaGPS"] if data["Llegadas"][0]["DistanciaGPS"] is not None else "-"
|
||||
bus_info["timeLabel"] = data["Llegadas"][0]["EstimadaGPS"] if data["Llegadas"][0]["EstimadaGPS"] is not None else "-"
|
||||
bus_info["route"] = data["Descripcion"][:-1] if data["Descripcion"] is not None else "-"
|
||||
bus_info["direction"] = data["Descripcion"][-1] if data["Descripcion"] is not None else "-"
|
||||
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_info["timeRemaining"] = int(abs(diff.total_seconds() // 60))
|
||||
data_main.append(bus_info)
|
||||
|
||||
return data_main
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#Exportando datos
|
||||
def export_data():
|
||||
X = api_request()
|
||||
data_main = lista_buses(X)
|
||||
data_time = sorted(data_main, key=lambda x: x['timeRemaining'],reverse=True)
|
||||
|
||||
data_x = (data_time[0],data_time[1])
|
||||
return data_x
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue