Advertisement
teknoraver

mannaggia-ng

Oct 25th, 2023 (edited)
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.18 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Versione riveduta e corretta di mannaggia.sh
  4. # problemi di mannaggia.sh:
  5. # * scarica solo la prima pagina di ogni lettera dell'alfabeto
  6. # * usa /dev/urandom per scegliere una lettera casuale (LOL!), quando Bash ha il supporto al random
  7. # * inutilmente complesso, il parsing dei tag veniva fatto con CINQUE PIPE, quando basta un solo awk scritto bene
  8. # released under GNU-GPLv3
  9.  
  10. prescegli() {
  11.     letter=$(awk '{printf("%c", $1)}' <<<$((RANDOM % 26 + 65)))
  12.     pages=$(curl -s https://www.santiebeati.it/$letter/ |awk -F'more|\\.html' '/Pagina:/{print $(NF-1);exit}')
  13.     local path=
  14.  
  15.     # Alcune lettere tipo Q e Z hanno una pagina soltanto
  16.     if [ -n "$pages" ]; then
  17.         page=$((RANDOM % pages + 1))
  18.         [ $page -ne 1 ] && path=more$page.html
  19.     fi
  20.  
  21.     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)
  22.     prescelto="Mannaggia a $santo"
  23. }
  24.  
  25. while : ; do
  26.     prescegli
  27.     echo $prescelto
  28.     mplayer -nocache -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=$prescelto&tl=it" &>/dev/null
  29.     sleep 3
  30. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement