jueves, 15 de septiembre de 2022

conky con: API openWeatherMap mas una brújula para indicar la dirección del viento y la luna observada desde la Patagonia Argentina

El fondo de escritorio es una fotografía de un atardecer en una de mis salidas en bicicleta por la costanera de Rio Gallegos (Argentina)

 

 descargue los archivos de configuración desde acá 

el contenido del archivo open-weather-map-wather-conky-master.zip descargado es el que se muestra a continuación:


Para utilizar esta configuración de conky,  hay que registrarse en OpenWeatherMap haciendo clic acá lo que le generará su propia API-KEY


 

Dentro de la carpeta scripts se encuentran los siguientes archivos. Uno de ellos tendrá que ser modificado por usted con su propia API-KEY de OpenWeatherMap luego de su registración.

 
 el script openWeatherMap-weather.sh

 
#!/bin/bash
# -------------------------------------------------------------------
# File: openWeatherMap-weather.sh
# Type: Bash Shell Script
# By Julio Alberto Lascano http://drcalambre.blogspot.com/
#________          _________        .__                ___.                  
#\______ \_______  \_   ___ \_____  |  | _____    _____\_ |_________   ____  
# |    |  \_  __ \ /    \  \/\__  \ |  | \__  \  /     \| __ \_  __ \_/ __ \ 
# |    `   \  | \/ \     \____/ __ \|  |__/ __ \|  Y Y  \ \_\ \  | \/\  ___/ 
#/_______  /__|     \______  (____  /____(____  /__|_|  /___  /__|    \___  >
#        \/                \/     \/          \/      \/    \/            \/ 
#
# Last modified:2022-09-15
# -------------------------------------------------------------------
# RGL : Rio Gallegos city, Argentina lat= -51.6226&lon=-69.2181
# To get information in JSON format: https://openweathermap.org/current#current_JSON
# For help: https://openweathermap.org/current#parameter
# -------------------------------------------------------------------
# 5 day weather forecast: https://openweathermap.org/forecast5
# You can search weather forecast for 5 days with data every 3 hours by geographic coordinates. 
# All weather data can be obtained in JSON and XML formats.
# [cnt]	optional A number of days, which will be returned in the API response (from 1 to 16)
# Example of API call: http://api.openweathermap.org/data/2.5/forecast/daily?q=London&cnt=3&appid={API key}
# -------------------------------------------------------------------
# API call
# api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&appid={API key} 
# https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API key}
# -------------------------------------------------------------------

# Current Weather
urlweather="https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API key}&units=metric&lang=es"
# Extended forecast Weather
urlforecast="api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&cnt=3&appid={API key}&units=metric&lang=es"

curl ${urlweather} -s -o ~/.cache/openweathermap.json
curl ${urlforecast} -s -o ~/.cache/openweathermap-forecast.json


El otro archivo que tendría que ser modificado por usted seria el que recaba los datos de las fases lunares. Yo para esta implementación he obtenido un muy buen script en bash GetMoon.sh que programo Fernando Gilli fernando<at>wekers(dot)org (mis respetos a él por el buen trabajo que hizo). 

Yo hice mi propia implementación de la manera que se muestra a continuación (usted es libre de adecuarlo al hemisferio en que vive para mostrar de manera correcta las fases lunares)



#!/bin/bash
# -------------------------------------------------------------------
# File: GetMoon.sh                                       /\
# Type: Bash Shell Script                               /_.\
# By Fernando Gilli fernandowekers(dot)org    _,.-'/ `",\'-.,_
# ------------------------                     -~^    /______\`~~-^~:
# Get Moon data from moongiant.com
# / OS : $Linux, $FreeBSD (X Window)
# ------------------------
# adapted for the current version by: 
#________          _________        .__                ___.                  
#\______ \_______  \_   ___ \_____  |  | _____    _____\_ |_________   ____  
# |    |  \_  __ \ /    \  \/\__  \ |  | \__  \  /     \| __ \_  __ \_/ __ \ 
# |    `   \  | \/ \     \____/ __ \|  |__/ __ \|  Y Y  \ \_\ \  | \/\  ___/ 
#/_______  /__|     \______  (____  /____(____  /__|_|  /___  /__|    \___  >
#        \/                \/     \/          \/      \/    \/            \/ 
# Julio Alberto Lascano http://drcalambre.blogspot.com/
# Last modified:2022-09-15
# -------------------------------------------------------------------

# Working directory
DirShell="$HOME/.cache"
# set language
lang="pt-es"

# put your hemisphere here:
# n for north
# s for south
hemisphere=s

# ****************************

wget -q -O ${DirShell}/raw "http://www.moongiant.com/phase/today" > /dev/null 2>&1
sleep 1
cp ${DirShell}/raw ${DirShell}/ico

[ -f ${DirShell}/moon_tmp.jpg ] && rm ${DirShell}/moon_tmp.jpg
[ -f ${DirShell}/moon.jpg ] && rm ${DirShell}/moon.jpg


sed -i -e '/^ *$/d' -e 's/^ *//g' ${DirShell}/raw
sed -i '/Illumination/!d' ${DirShell}/raw
sed -i 's/
/\n/g' ${DirShell}/raw sed -i 's|<[^>]*>||g' ${DirShell}/raw sed -i -e '4d' ${DirShell}/raw #ico name sed -i '/var jArray=\|"todayMoonContainer"/!d' ${DirShell}/ico sed -i -e 's/"\]};//g' -e 's/^.*today_phase\///g' -e 's/\.jpg.*$//g' ${DirShell}/ico cat ${DirShell}/ico >> ${DirShell}/raw img_in=$(sed -n 4p ${DirShell}/raw) [ -f ${DirShell}/ico ] && rm ${DirShell}/ico now=$(date --date="now" +%H) # Moon image if [[ $now -ge 18 || $now -lt 06 ]]; then # $now >=18 or $now < 06 --> day moon -> more light wget -q --output-document=${DirShell}/moon_tmp.jpg https://www.moongiant.com/images/today_phase/$img_in.jpg > /dev/null 2>&1 else # night moon -> dark # Can't download direct with wget # To get moon image -> Pass Cloudflare DDOS Protection curl https://static.die.net/moon/210.jpg --output "${DirShell}"/moon_tmp.jpg \ -H 'Host: static.die.net' \ -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0' \ -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \ -H 'Accept-Language: en-US,en;q=0.5' \ -H 'Referer: https://static.die.net/moon' \ -H 'Connection: keep-alive' --compressed fi # mirror moon image, hemisphere south case $hemisphere in s) convert -flop -colorspace rgb ${DirShell}/moon_tmp.jpg ${DirShell}/moon.jpg rm ${DirShell}/moon_tmp.jpg ;; *) convert -colorspace rgb ${DirShell}/moon_tmp.jpg ${DirShell}/moon.jpg rm ${DirShell}/moon_tmp.jpg ;; esac # Translate pt-es (moon phase name) case $lang in pt-es) sed -i -e 's/New Moon/Luna Nueva/g' ${DirShell}/raw sed -i -e 's/Full Moon/Luna Llena/g' ${DirShell}/raw sed -i -e 's/Waxing Crescent/Luna Creciente/g' ${DirShell}/raw sed -i -e 's/Waxing Gibbous/Luna Menguante/g' ${DirShell}/raw sed -i -e 's/Waning Crescent/Creciente Menguante/g' ${DirShell}/raw sed -i -e 's/Waning Gibbous/Luna Menguante/g' ${DirShell}/raw sed -i -e 's/First Quarter/Cuarto Creciente/g' ${DirShell}/raw sed -i -e 's/Last Quarter/Cuarto Minguante/g' ${DirShell}/raw ;; esac # exec too bash ~/.config/conky/scripts/lune_die.sh > /dev/null 2>&1 #EOF

Con esto ya estaría en condiciones de volcar sus modificaciones en el lugar adecuado para que conky lea el archivo de configuración conky.conf de manera correcta:

vuelque sus archivos y carpetas en $HOME/.config/conky/


Para poder trabajar con archivos JSON es necesario instalar la utilidad jq

Con el comando jq puede transformar JSON de varias maneras, seleccionando, iterando, reduciendo y alterando documentos JSON. Yo lo utilizo desde conky.conf para ir recuperando los datos que ya se han descargado con la llamada a la API de openweathermap.

Para ello abra una terminal y como root instale jq  (Command-line JSON processor)


También para realizar ciertas operaciones matemáticas, buscar palabras,  patrones de palabras y reemplazarlos por otras palabras y/o patrones yo utilizo awk

Para ello desde la terminal y como root instale gawk


Para mostrar correctamente la luna en el hemisferio sur (Argentina) se hace uso de convert 

convert forma parte del paquete imagemagick . Instálelo como sigue: 


Los datos en formato json son traídos con la api de openweathermap.org mediante curl
Instálelo como sigue: 


Los datos de la Luna se obtienen desde el módulo Perl Astro::MoonPhasecon 

Con su o sudo desde la terminal necesita instalar el módulo perl mediante:




Luego ejecute desde su terminal el siguiente comando para que el escrip haga una primera llamada a la api de openweathermap para que genere los archivos json necesarios para que conky pueda mostrar por primera vez los datos necesarios y no ocasione ningún error. Conky luego seguirá haciendo las llamadas correspondientes.

Luego de ejecutar el script, este realizara una llamada a la API de openweathermap y generará por primera ves los archivos json



Con esto quedaría finalizado el instructivo y ya estaría en condiciones de correr conky desde cualquier terminal.



No hay comentarios.:

Publicar un comentario