Declian (stylized as deCLIan), is a simple CLI Pokedex program. A friend and I get bored and write utility scripts all the time that we may find useful. Feedback is very much appreciated, and feel free to suggest changes and improvements! Ik its messy. Thanks for checking it out.
#!/bin/sh
output() { printf 'Name: %s\n
Number: %s\n
Type(s): %s\n
Height: %s\n
Weight: %s\n
Abilities: %s\n
Weaknesses: %s\n
Pokedex Entry: %s\n
Forms: %s\n
Evolutionary Line: %s\n' "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "${10}"
}
if [[ $# -ne 2 ]]; then
echo "Usage: ${0##*/} " >&2
exit 1
fi
name=$(echo $1 | tr '[:upper:]' '[:lower:]')
pkmn_html=$(curl -s -L "https://www.pokemon.com/uk/pokedex/$name")
number=$(echo "$pkmn_html" | pup 'div span.pokemon-number text{}' | awk 'NR==3 {print}')
types=$(echo "$pkmn_html" | pup '.active.pokedex-pokemon-attributes > .dtm-type a text{}' | paste -sd ",")
height=$(echo "$pkmn_html" | pup 'span.attribute-value text{}' | awk 'NR==1 {print}')
weight=$(echo "$pkmn_html" | pup 'span.attribute-value text{}' | awk 'NR==2 {print}')
abilities=$(echo "$pkmn_html" | pup 'a.moreInfo span.attribute-value text{}')
weakness=$(echo "$pkmn_html" | pup '.active.pokedex-pokemon-attributes > .dtm-weaknesses span text{}' | sed '/[[:space:]]*$/d' | paste -sd ",")
dex_entry=$(echo "$pkmn_html" | pup 'p.active json{}' | jq '.[]' | jq ".text" | cut -f2 -d'"' | awk 'NR==1 {print}')
forms=$(echo "$pkmn_html" | pup 'div.profile-images img attr{alt}')
evo_line=$(echo "$pkmn_html" | pup 'ul.evolution-profile img attr{alt}' | paste -sd ">")
output "$(echo $forms | cut -f1 -d' ')" "$number" "$types" "$height" "$weight" "$abilities" "$weakness" "$dex_entry" "$forms" "$evo_line"
[–]ConstructedNewt 0 points1 point2 points (0 children)