Talk Weather - Anúncio do tempo e temperatura em voz sintetizada
Publicado por Khayla Elias dos Santos (última atualização em 25/09/2015)
[ Hits: 6.731 ]
Homepage: https://linktr.ee/khayla.elias
Download 1442259524.talk-weather (versão 2)
Este script permite a exibição do tempo (temperatura, umidade relativa do ar e outros) de uma determinada localidade através do terminal. Além de atualizar e exibir periodicamente os dados, este código permite o anúncio do tempo em voz sintetizada. Para ver como usá-lo, leia o comentário nas primeiras linhas do código.
Pré-requisito: é necessário ter instalado os pacotes do espeak.
Sugestão de uso: rodar em uma das janelas do "Screen" ou do "Terminator".
Versão 2 - Enviado por Khayla Elias dos Santos em 14/09/2015
Changelog: talk-weather (version 2 - 2015.09.14)
Últimas atualizações:
- Inclusão do help através da opção --help.
- Incluída três opções de perfil: silencioso; voz com pausador do 'mocp'; e default, somente com voz.
- Verificação dos parâmetros de entrada e outras (sanity checks).
- Reimplementação do tratamento de flexão gramatical (singular/plural).
Download 1442259524.talk-weather
#!/bin/bash
# Description: get, talk and display weather data of station selected.
#
# Parameters:
# 1) CODE: station code of local (get in http://www.nws.noaa.gov/tg/siteloc.shtml)
# 2) INTERVAL: interval to updade data (in minutes)
# 3) QUIET: desable speech synthesizer when weather is updated (use -q )
#
# General use:
# talk-weather [CODE [INTERVAL [-q]]]
# Examples of use:
# talk-weather SBCF
# talk-weather SCSP 15
# talk-weather SLLP 30 -q
#
# By: Alexandre Elias dos Santos (aleniac@ufmg.br)
# Date: July 2015
intervalo=$2; intervalo=${intervalo:=20} # intervalo de atualização
intervalo=$(($intervalo*60)) # conversão de intervalo para segundos
[ "$intervalo" -eq 0 ] && intervalo=1200
DIR="$HOME/.wmWeatherReports"
COD="`echo "$1"|cut -c -4|tr '[:lower:]' '[:upper:]'`"
COD="`echo ${COD:=SBBH}`" # define por default a estação de Belo Horizonte
FILE="http://weather.noaa.gov/pub/data/observations/metar/decoded/$COD.TXT"
UPDATE0="`ls -ltu $DIR/$COD.TXT 2>/dev/null|sed 's/ */ /g'|cut -d' ' -f 6-8|sed 's/[ :]//g'`"
UPDATE="$UPDATE0" # flag de update
QUIET=$3 # desable talk
QUIET=${QUIET:=null}
# vetor rosa do vento
declare -A ROSA=([N]=Norte [NNE]=Nor-nordeste [NE]=Nordeste [ENE]=Lés-nordeste
[E]=Leste [ESE]=Lés-sudeste [SE]=Sudeste [SSE]=Su-sudeste
[S]=Sul [SSW]=Su-sudoeste [SW]=Sudoeste [WSW]=Oés-sudoeste
[W]=Oeste [WNW]=Oés-noroeste [NW]=Noroeste [NNW]=Nor-noroeste [null]=null)
if [ ! -d $DIR ]; then
mkdir $DIR
fi # verifica existencia do diretorio de trabalho
cd $DIR
clear
printf "To get $COD each $(($intervalo/60)) minutes."
[ "$QUIET" = "-q" ] && printf " Quiet."
sleep 3
while true; do
clear
printf "Downloading $COD... "; tput cup 0 0
wget -qN $FILE || printf "\e[31;1mwget (`date +%H:%M:%S`): error to get file $COD.TXT\e[m\n"
if [ -f $DIR/$COD.TXT ]; then
printf "\e[1;36m`egrep "[0-9]-[0-9]|UTC" $DIR/$COD.TXT`\n"
# EXTRAI DADOS DO ARQUIVO
estacao="`grep "[0-9]-[0-9]" $DIR/$COD.TXT|sed 's/ *,.*//'`"; estacao=${estacao:=Estação desconhecida}
temperatura="`grep Temp $DIR/$COD.TXT|cut -d"(" -f2|cut -d" " -f1`"; temperatura=${temperatura:=null}
humid="`grep Hum $DIR/$COD.TXT|sed 's/.*:.//'|sed 's/%//'`"; humid=${humid:=null}
est="`ls -ltu $DIR/$COD.TXT 2>/dev/null|sed 's/ */ /g'|cut -d' ' -f 6-8|sed -r 's/ [0-9][0-9]:/,&/'`"; est=${est:=null}
from="`grep Wind: $DIR/$COD.TXT| cut -d" " -f4`"; from=${from:=null}
angulo="`grep Wind: $DIR/$COD.TXT|sed -r "s/^.*\(([0-9][0-9]*) deg.*$/\1/"`"; angulo=${angulo:=null}
velocidade="`grep Wind: $DIR/$COD.TXT|sed -r 's/^.*at ([0-9][0-9]*).MPH.*$/\1/'`"; velocidade=${velocidade:=null}
grep -q "Calm:0" $DIR/$COD.TXT
if [ "$?" = 0 ]; then
wind="Vento calmo."
else wind="Vento à $velocidade milhas por hora, vindo do ${ROSA[$from]}."
fi
sky="`grep Sky $DIR/$COD.TXT|sed 's/.*:.//'`"
weather="`grep Weat $DIR/$COD.TXT|sed 's/.*:.//'`"
############################
printf '\e[33mTemperature:\e[m%s\n' " $temperatura °C"
printf '\e[1;33mWind:\e[m%s\n' "`grep "^Wind:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Win.*ill:" $DIR/$COD.TXT && printf '\e[1;33mWindchill:\e[m%s\n' "`grep "^Win.*ll:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Vis.*:" $DIR/$COD.TXT && printf '\e[1;33mVisibility:\e[m%s\n' "`grep "^Vis.*:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Sky.*:" $DIR/$COD.TXT && printf '\e[1;33mSky conditions:\e[m%s\n' "`grep "^Sky.*:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Weather:" $DIR/$COD.TXT && printf '\e[1;33mWeather:\e[m%s\n' "`grep "^Wea.*:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Precip.*:" $DIR/$COD.TXT && printf '\e[1;33mPrecipitation last hour:\e[m%s\n' "`grep "^Precip.*:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Heat.*:" $DIR/$COD.TXT && printf '\e[1;33mHeat index:\e[m%s\n' "`grep "^Heat.*:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "Dew.*:" $DIR/$COD.TXT && printf '\e[1;33mDew Point:\e[m%s\n' "`grep "^Dew.*t:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Relat.*:" $DIR/$COD.TXT && printf '\e[1;33mRelative Humidity:\e[m%s\n' "`grep "^Relat.*:" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Press.*):" $DIR/$COD.TXT && printf '\e[1;33mPressurre (altimeter):\e[m%s\n' "`grep "^Press.*):" $DIR/$COD.TXT|cut -d":" -f2`"
grep -q "^Press.*y:" $DIR/$COD.TXT && printf '\e[1;33mPressurre tendency:\e[m%s\n' "`grep "^Press.*y:" $DIR/$COD.TXT|cut -d":" -f2`"
### grep -q "^ob:" $DIR/$COD.TXT && printf '\e[1;33mob:\e[m%s\n' "`grep "^ob:" $DIR/$COD.TXT|sed 's/ob://'`"
grep -q "^cycle:" $DIR/$COD.TXT && printf '\e[1;33mcycle:\e[m%s' "`grep "^cycle:" $DIR/$COD.TXT|cut -d":" -f2`"
UPDATE0="`ls -ltu $DIR/$COD.TXT 2>/dev/null|sed 's/ */ /g'|cut -d' ' -f 6-8|sed 's/[ :]//g'`"
if [ "$QUIET" != "-q" ] && [ "$UPDATE" != "$UPDATE0" ]; then
UPDATE="$UPDATE0"
temp="`echo "scale=1; ($temperatura^2)/1"|bc`"
if [ "$temp" = "1.0" ]; then
grau="grau"
negativo="negativo"
temp="`echo "scale=0; $temperatura/1"|bc`"
else grau="graus"
negativo="negativos"
fi # faz tratamento de plural
if [ "`echo "scale=0; 10*$temperatura/1"|bc`" -lt 0 ]; then
if [ "$temp" = "-1" ]; then
temp=1
else
if [ `echo "$temperatura"|grep -q "\."; echo $?` = 0 ]; then
temp="`echo "scale=1; $temperatura/(-1)"|bc`"
else
temp=$((-1*$temperatura))
fi
fi
temp="`echo $temp|sed 's/^\./0\./'`"
temp="$temp $grau $negativo"
else
if [ "$temp" != "1" ]; then
temp="`echo $temperatura|sed 's/^\./0\./'`"
fi
temp="$temp $grau"
fi # faz tratamento de negativos
( # talking weather...
pausado="" # estado do mocp (Muscic On Console Player)
mocp -i|head -1|grep -q "PAUSE" &>/dev/null && pausado="on"
mocp -P &>/dev/null # unpaused mocp
espeak -k -20 -ven-us+m2 "$HOSTNAME: weather:"
espeak -k -20 -vpt+f2 "Em $estacao, `echo $temp|sed 's/\./ponto/'`. Humidade relativa do ar: $humid por cento."
[ -n "$sky" ] && espeak -k -20 -ven-us+m2 "Sky conditions: $sky`[ -n "$weather" ] && echo ","` $weather."
[ $((`date +%H|sed 's/^0//'` % 3)) -eq 0 ] && espeak -k -20 -vpt+f2 "$wind"
[ "$pausado" = "on" ] || mocp -U &>/dev/null # unpased mocp
)
fi # saida de voz - tempo e temperatura
fi
sleep $intervalo
done # atualiza e exibe os dados periodicamente
adicionar um gerenciador de janelas a lista do kdm
organização_topografia segundo arquivo
Varredura com Nmap a procura do serviço Apache
Como atualizar sua versão estável do Debian
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Script de montagem de chroot automatica
Atualizar Linux Mint 22.2 para 22.3 beta
Jogar games da Battle.net no Linux com Faugus Launcher
Como fazer a Instalação de aplicativos para acesso remoto ao Linux
Por que passar nas disciplinas da faculdade é ruim e ser reprovado é b... (7)
De volta para o futuro - ou melhor, para o presente (parte 2) (0)









