Skip to content

Instantly share code, notes, and snippets.

@eightbitraptor
Created January 19, 2012 11:48
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 eightbitraptor/1639558 to your computer and use it in GitHub Desktop.
Save eightbitraptor/1639558 to your computer and use it in GitHub Desktop.
get a random pokemon name
#!/bin/bash
#cat pokedex.html | grep '<tr>' -A 3 | grep 'title=' | cut -d' ' -f 7 | sed -e 's/.*\>\(.*\)<\/a>/\1/'
main(){
echo `random_pokemon`
}
random_pokemon() {
index=`expr $RANDOM \% $(count) + 1`
pokedex | head -$index | tail -n 1
}
count() {
pokedex | wc -l
}
pokedex(){
grab_pokemon | extract_table | parse_name | strip_invalid_names | downcase
}
grab_pokemon() {
if [[ -f '/tmp/pokedex.data' ]]; then
cat /tmp/pokedex.data
else
curl http://pokemon.wikia.com/wiki/List_of_Pok%C3%A9mon | tee /tmp/pokedex.data
fi
}
extract_table() {
cat pokedex.html | grep '<tr>' -A 3
}
parse_name(){
grep 'title=' | cut -d' ' -f 7 | sed -e 's/.*\>\(.*\)<\/a>/\1/'
}
strip_invalid_names() {
grep -v '[^[:alpha:]]'
}
downcase() {
tr 'A-Z' 'a-z'
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment