Advertisement
Guest User

stalker.sh

a guest
Dec 15th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo "Quantos senadores você quer stalkear?"
  4. read max
  5. echo "A partir de qual ID o programa deve começar?"
  6. read id
  7.  
  8. echo "---------------"
  9. count=1
  10.  
  11. aux="/home/jose/tmp"
  12. img="/home/jose/img.jpg"
  13. pasta="/home/jose/senadores"
  14.  
  15. range1="<dl class=\"dl-horizontal\">"
  16. range2="</dl>"
  17. from1="<dt>"
  18. to1="</dt>"
  19. from2="<dd>"
  20. to2="</dd>"
  21.  
  22. if [ -d "$pasta" ]; then
  23.     rm -rf $pasta
  24. fi
  25. mkdir $pasta
  26.  
  27. while [ $count -le  $max ]; do
  28.     # DEBUG
  29.     echo "COUNT: $count"
  30.     echo "ID: $id"
  31.    
  32.     wget -q www6g.senado.leg.br/transparencia/sen/$id -O $aux
  33.     notfound=`sed -n '/Desculpe/{p}' $aux`
  34.     if [ ! "$notfound" ]; then
  35.         wget -q www.senado.gov.br/senadores/img/fotos-oficiais/senador$id.jpg -O $img
  36.         if [ ! $? -ne 0 ]; then
  37.             cp $aux senador.html
  38.  
  39.             # DELIMITA RANGE
  40.             a="$(cat $aux)"; a="$(echo "${a#*$range1}")"; aux2="$range1${a%%$range2*}$range2"; grep -v "$aux2" $aux > temp && mv temp $aux
  41.             aux2=`sed -e "s:$range1::g" <<< $aux2`; aux2=`sed -e "s:$range2::g" <<< $aux2`;  aux2=`sed -e 's/   //g' <<< $aux2`
  42.             rm $aux
  43.             echo "$aux2" >> $aux
  44.             cat $aux  | xargs > tmp2
  45.             cat tmp2 > $aux
  46.             rm tmp2
  47.  
  48.             sed -i 's:</dt>:</dt>\r\n:g' $aux
  49.             sed -i 's:</dd>:</dd>\r\n:g' $aux
  50.  
  51.             # NOME
  52.             a="$(cat $aux)"; a="$(echo "${a#*$from1}")"; linha="$from1${a%%$to1*}$to1"; grep -v "$linha" $aux > temp && mv temp $aux
  53.             linha=`sed -e "s:$from1::g" <<< $linha`; linha=`sed -e "s:$to1::g" <<< $linha`
  54.            
  55.             a="$(cat $aux)"; a="$(echo "${a#*$from2}")"; nome="$from2${a%%$to2*}$to2"; grep -v "$nome" $aux > temp && mv temp $aux
  56.             # tirando tags HTML da string
  57.             nome=`sed -e "s:$from2::g" <<< $nome`; nome=`sed -e "s:$to2::g" <<< $nome`
  58.  
  59.             mkdir "$pasta/$nome"
  60.             mv senador.html "$pasta/$nome/senador.html"
  61.             touch "$pasta/$nome/dados.txt"
  62.             echo "ID: $id" >> "$pasta/$nome/dados.txt"
  63.             echo "$linha $nome" >> "$pasta/$nome/dados.txt"
  64.  
  65.             while grep -q "$from1" $aux; do
  66.                 a="$(cat $aux)"; a="$(echo "${a#*$from1}")"; linha1="$from1${a%%$to1*}$to1"; grep -v "$linha1" $aux > temp && mv temp $aux
  67.                 # tirando tags HTML da string
  68.                 linha1=`sed -e "s:$from1::g" <<< $linha1`; linha1=`sed -e "s:$to1::g" <<< $linha1`
  69.                
  70.                 #DEBUG
  71.                 #echo "LINHA1: $linha1"
  72.  
  73.                 a="$(cat $aux)"; a="$(echo "${a#*$from2}")"; linha2="$from2${a%%$to2*}$to2"; grep -v "$linha2" $aux > temp && mv temp $aux
  74.                 # tirando tags HTML da string
  75.                 linha2=`sed -e "s:$from2::g" <<< $linha2`; linha2=`sed -e "s:$to2::g" <<< $linha2`
  76.  
  77.                 if [[ $linha2 =~ .*\<a.* ]]; then
  78.                     echo "$linha2" >> temp
  79.                     from3="href="; to3=">"; a="$(cat temp)"; a="$(echo "${a#*$from3}")"; linha2="$from3${a%%$to3*}$to3";
  80.                     linha2=`sed -e "s/mailto://g" <<< $linha2`; linha2=`sed -e "s/href=//g" <<< $linha2`; linha2=`sed -e "s/>//g" <<< $linha2`
  81.                     rm temp
  82.                 fi
  83.                
  84.                 #DEBUG
  85.                 #echo "LINHA2: $linha2"
  86.  
  87.                 echo "$linha1 $linha2" >> "$pasta/$nome/dados.txt"
  88.             done
  89.            
  90.             rm $aux
  91.             mv $img "$pasta/$nome/$nome.jpg"
  92.            
  93.             (( count++ ))
  94.         fi
  95.     fi
  96.     (( id++ ))
  97.     echo "---------------"
  98. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement