forked from TDTP/pantallas-led
Scripts de instalacion y primera ejecucion
parent
659738a0c2
commit
b66bd8fe0c
|
@ -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
|
|
@ -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 $?
|
||||
|
||||
|
||||
|
|
@ -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 <<EOF | sudo tee /etc/modprobe.d/blacklist-rgb-matrix.conf > /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
|
Loading…
Reference in New Issue