From b66bd8fe0c4080e617eff137aab628485a21e6fa Mon Sep 17 00:00:00 2001 From: Alonso Diaz Candia Date: Wed, 6 Dec 2023 14:49:17 +0000 Subject: [PATCH] Scripts de instalacion y primera ejecucion --- GenPoster/getData.py | 72 +++++++++++++++++++++++++++++++++++++++++++ ejecucion_script.py | 43 ++++++++++++++++++++++++++ instalation_script.sh | 52 +++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 GenPoster/getData.py create mode 100644 ejecucion_script.py create mode 100644 instalation_script.sh diff --git a/GenPoster/getData.py b/GenPoster/getData.py new file mode 100644 index 0000000..8424193 --- /dev/null +++ b/GenPoster/getData.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 + +import requests +import json + + +class Paradero: + def __init__(self): + # Dispositivo + self.id = "00000000160f3b42b8:27:eb:0f:3b:42" + + # Autentificación data + self.url_auth = 'https://transporte.hz.kursor.cl/api/auth/' + self.username = "usuario1" + self.password = "usuario1" + + # Token obtenido luego del 'login' + self.token = self.__get_token() + print(self.token) + + # URL de la API para obtener los datos de los recorridos + self.url_getinfodevice = 'https://transporte.hz.kursor.cl/api/dispositivos/getInfoDevice/' + self.data = None + + + def __get_token(self): + auth = '''{ + "username": "usuario1", + "password": "usuario1" + }''' + + response = requests.post(self.url_auth, data=auth) + + # Estado de la respuesta + if response.status_code == 200: + return response.json()['token'] + else: + return None + + def get_data(self): + # Datos para la solicitud + data_getinfodevice = { + "GetInfoDevice": { + "idDispositivo": self.id, + "KeyAuthorizacion": "tokenSinUso" #Autentificacion de mentira sisisi + } + } + + if self.token is not None: + #Aquí se ingresa el token obtenido anteriormente + headers_getinfodevice = { + 'Authorization': f'Bearer {self.token}', + 'Content-Type': 'application/json' + } + + # Request + response = requests.post(self.url_getinfodevice, json=data_getinfodevice, headers=headers_getinfodevice) + + self.data = self.__serialize_data(response) + return self.data + + def __serialize_data(self, response): + data = response.json() + data = data["GetInfoDeviceResponse"]["DetalleLineas"][0] + + 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"][:-3] 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 "-" + + return bus_info \ No newline at end of file diff --git a/ejecucion_script.py b/ejecucion_script.py new file mode 100644 index 0000000..f467ae1 --- /dev/null +++ b/ejecucion_script.py @@ -0,0 +1,43 @@ +#!/bin/bash + +# Función para verificar el código de retorno +verificar_codigo_retorno() { + if [ $1 -eq 0 ]; then + echo "[OK]" + # Agrega aquí el código para el siguiente paso + else + echo "Hubo un error en el comando. Abortando el script." + exit 1 # Termina el script con un código de retorno no exitoso + fi +} + +echo -n "Instalando librerias necesarias " +sudo apt update > /dev/null 2>&1 +sudo apt-get install python3-dev python3-pillow -y > /dev/null 2>&1 + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + +echo -n "Entrando al repositorio " +cd $HOME/rpi-rgb-led-matrix/bindings/python + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + +echo -n "Instalando rpi-rgb-led-matrix " +make build-python PYTHON=$(command -v python3) > /dev/null 2>&1 +sudo make install-python PYTHON=$(command -v python3) > /dev/null 2>&1 + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + +echo -n "Clonando repositorio FIC " +cd $HOME +git clone https://github.com/diegoalrv/pantallas-led > /dev/null 2>&1 +cd pantallas-led + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + + + diff --git a/instalation_script.sh b/instalation_script.sh new file mode 100644 index 0000000..6b36f0a --- /dev/null +++ b/instalation_script.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Función para verificar el código de retorno +verificar_codigo_retorno() { + if [ $1 -eq 0 ]; then + echo "[OK]" + # Agrega aquí el código para el siguiente paso + else + echo "Hubo un error en el comando. Abortando el script." + exit 1 # Termina el script con un código de retorno no exitoso + fi +} + +# Instalación de bibliotecas +echo -n "Actualizando repositorios " +sudo apt update > /dev/null 2>&1 + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + +echo -n "Instalando git " +sudo apt install git -y > /dev/null 2>&1 + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + +echo -n "Clonando repo de la matriz led " +git clone https://github.com/hzeller/rpi-rgb-led-matrix.git > /dev/null 2>&1 + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + +echo -n "Desactivando tarjeta de sonido " +cat < /dev/null 2>&1 +blacklist snd_bcm2835 +EOF +sudo update-initramfs -u > /dev/null 2>&1 + +# Verificar el código de retorno llamando a la función +verificar_codigo_retorno $? + +tiempo=5 + +echo "El equipo se apagará en: " +while [ $tiempo -gt 0 ]; do + echo $tiempo + sleep 1 + tiempo=$((tiempo-1)) +done + +echo "¡Apagando el equipo ahora!" +shutdown -h now