Skip to content

Instantly share code, notes, and snippets.

@teknoraver
Created October 25, 2023 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teknoraver/0041125e68d2b3b9947f0e7895562243 to your computer and use it in GitHub Desktop.
Save teknoraver/0041125e68d2b3b9947f0e7895562243 to your computer and use it in GitHub Desktop.
Improved mannaggia.sh
#!/bin/bash
# Versione riveduta e corretta di mannaggia.sh
# problemi di mannaggia.sh:
# * scarica solo la prima pagina di ogni lettera dell'alfabeto
# * usa /dev/urandom per scegliere una lettera casuale (LOL!), quando Bash ha il supporto al random
# * inutilmente complesso, il parsing dei tag veniva fatto con CINQUE PIPE, quando basta un solo awk scritto bene
# released under GNU-GPLv3
prescegli() {
letter=$(awk '{printf("%c", $1)}' <<<$((RANDOM % 26 + 65)))
pages=$(curl -s https://www.santiebeati.it/$letter/ |awk -F'more|\\.html' '/Pagina:/{print $(NF-1);exit}')
local path=
# Alcune lettere tipo Q e Z hanno una pagina soltanto
if [ -n "$pages" ]; then
page=$((RANDOM % pages + 1))
[ $page -ne 1 ] && path=more$page.html
fi
santo=$(curl -s "https://www.santiebeati.it/$letter/$path" |awk -F'<FONT SIZE="-2">|</FONT> <FONT SIZE="-1"><b>|</b>' '/<a href="\/dettaglio\/.*<FONT/{print $2,$3}' |iconv -f ISO-8859-1 |shuf -n1)
prescelto="Mannaggia a $santo"
}
while : ; do
prescegli
echo $prescelto
mplayer -nocache -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=$prescelto&tl=it" &>/dev/null
sleep 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment