Pon un Chuck Norris en tu vida! O mejor aun, pon miles de Chuck Facts en tu consola!
Bored STenyaK Productions presents: chuckfacts.sh!

Coming this winter to a console in front of you…
#!/bin/bash
# check for parameters
if [ -z $1 ]
then
echo "Please specify the destination chuck norris facts file."
echo "E.g.: $0 ~/.chuckfacts.txt"
exit
fi
ffile=$1
old=0
if [ -s $ffile ]
then
old=$(wc -l $ffile |sed "s/\s.*//g")
fi
echo -n "Getting facts pack"
# download the 170 first chuck norris pages of 4q.cc site to disk
for i in $(seq 1 170)
do
echo -n " $i"
# only store facts
wget -qO - \
"http://4q.cc/index.php?pid=listfacts&person=chuck&page=$i" \
| grep "index.php?pid=fact&person=chuck" >> $ffile
done
echo ""
echo -n "Post-processing facts..."
# remove unnecessary html code
perl -pi -e "s/.*id=.{32,32}\">//g;s/<\/a>.*//g" $ffile
# replace most common html entities
perl -pi -e "s/"/\"/g" $ffile
perl -pi -e "s/&/&/g" $ffile
# remove empty lines
perl -ni -e "print unless /pid=/" $ffile
# remove redundant lines
cat $ffile |sort |uniq > /tmp/chuckfacts.tmp
mv /tmp/chuckfacts.tmp $ffile
new=$(wc -l $ffile |sed "s/\s.*//g")
echo " OK"
echo "Generated $(($new-$old)) new facts ($new in total) facts."
# show how to add a fortune-like command to bashrc
echo ""
echo "You can add this to your ~/.bashrc file:"
echo 'test -s '$ffile' && cowsay -f $(ls /usr/share/cowsay/cows
| shuf |head -1) "$(cat '$ffile' |shuf |head -1)"'
Mira que no me aburro a veces ni nada eh…
December 18th, 2009 at 09:02
Qué grande! No conocía el “cowsay”, y es muy chulo.
Lo único, deberías poner el fichero para descargar, o pon un “\” en las dos líneas donde haces el wget, porque al hacer copy-paste eso sale como tres líneas y el wget se queja.
Yo ya lo he añadido a mi bashrc.
December 18th, 2009 at 09:50
Qué raro, anoche probé a copiarpegar y al ejecutarlo me tiró way…
March 26th, 2010 at 16:18
Wow thats baaaaaaddddd.
May 3rd, 2010 at 15:38
LOL!!!!!! chuck norris is amazing!!!!!
June 3rd, 2010 at 18:01
its chuck norris can swim through land… leave now
August 18th, 2011 at 05:10
it would have been beta if it said jesus can walk on water, but chuck norris can swim on land