try/except

This commit is contained in:
Eric Lay 2023-04-17 03:28:49 -05:00
parent 1dfeae3711
commit 01db495300
7 changed files with 26 additions and 78 deletions

View File

@ -13,8 +13,9 @@ help() {
### Pokedex viewer using pokemon-colorscripts and fzf ### Pokedex viewer using pokemon-colorscripts and fzf
fuzzy_pokedex() { fuzzy_pokedex() {
pokemon-colorscripts -l | POKEDATA="/home/ez/Git/fuzzy-pokedex/pokeData/"
fzf +m -s -i \ pokemon-colorscripts -l | sort |
fzf -q "$1" +m -s -i \
--cycle \ --cycle \
--reverse \ --reverse \
--prompt=' ' \ --prompt=' ' \
@ -27,20 +28,22 @@ fuzzy_pokedex() {
--info=inline:' 󰨉 ' \ --info=inline:' 󰨉 ' \
--color='fg+:15,fg:42,preview-fg:15,label:9,preview-label:15,hl+:134,hl:123,query:134,gutter:0,border:9,prompt:15,pointer:15,marker:15' \ --color='fg+:15,fg:42,preview-fg:15,label:9,preview-label:15,hl+:134,hl:123,query:134,gutter:0,border:9,prompt:15,pointer:15,marker:15' \
--tiebreak=begin,chunk,length \ --tiebreak=begin,chunk,length \
--preview="echo; pokemon-colorscripts -n {1} --no-title; cat /home/ez/Git/fuzzy-pokedex/pokeData/{1}" \ --preview="echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA{1}" \
--preview-window=68%:wrap:border-rounded \ --preview-window=68%:wrap:border-rounded \
--bind=focus:transform-preview-label:'echo [ {1} ] ' \ --bind=focus:transform-preview-label:'echo [ {1} ] ' \
--bind=ctrl-h:preview:'echo; ./fuzzy-pokedex -h;' \ --bind=ctrl-h:preview:"echo; ./fuzzy-pokedex -h;" \
--bind=ctrl-b:preview:'echo; pokemon-colorscripts -b -n {1} --no-title; cat /home/ez/Git/fuzzy-pokedex/pokeData/{1};' \ --bind=ctrl-b:preview:"echo; pokemon-colorscripts -b -n {1} --no-title; cat $POKEDATA{1};" \
--bind=ctrl-s:preview:'echo; pokemon-colorscripts -s -n {1} --no-title; cat /home/ez/Git/fuzzy-pokedex/pokeData/{1};' \ --bind=ctrl-s:preview:"echo; pokemon-colorscripts -s -n {1} --no-title; cat $POKEDATA{1};" \
--bind=ctrl-n:preview:'echo; pokemon-colorscripts -n {1} --no-title; cat /home/ez/Git/fuzzy-pokedex/pokeData/{1};' | --bind=ctrl-n:preview:"echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA{1};" |
parallel pokemon-colorscripts --no-title -n {} "&&" cat /home/ez/Git/fuzzy-pokedex/pokeData/{} parallel pokemon-colorscripts --no-title -n {} "&&" cat "$POKEDATA"{}
} }
### Update Pokemon stats file set ### Update Pokemon stats file set
update_pokeData() { update_pokeData() {
POKEINFO="/home/ez/Git/fuzzy-pokedex/pokeinfo"
POKEDATA="/home/ez/Git/fuzzy-pokedex/pokeData/"
echo -e "\n\t\tWARNING!!!\n\tThis WILL take a long time\n" echo -e "\n\t\tWARNING!!!\n\tThis WILL take a long time\n"
pokemon-colorscripts -l | sort | parallel --bar --color -j 200% /home/ez/Git/fuzzy-pokedex/pokeinfo {} ">" /home/ez/Git/pokedex/pokeData/{} pokemon-colorscripts -l | sort | parallel --bar --color --retry-failed -j 200% "$POKEINFO" {} ">" "$POKEDATA"{}
} }
if [[ ! "$1" =~ ^- ]]; then if [[ ! "$1" =~ ^- ]]; then

View File

@ -1,15 +0,0 @@
Name: Drampa
Pokedex Number: 780
Gender Ratio:  ♂:50.2% ♀:49.8%
Abilities: Berserk - Sap Sipper - Cloud Nine (Hidden Ability)
Base Stats
----------------------
Total: 485
Hp: 78
Attack: 60
Defence: 85
Special Attack: 135
Special Defence: 91
Speed: 36

View File

@ -1,15 +0,0 @@
Name: Necrozma
Pokedex Number: 800
Gender Ratio: Genderless
Abilities: Prism Armor
Base Stats
----------------------
Total: 600
Hp: 97
Attack: 113
Defence: 109
Special Attack: 157
Special Defence: 127
Speed: 77

View File

@ -1,15 +0,0 @@
Name: Nidoran-M
Pokedex Number: 032
Gender Ratio:  ♂:100% ♀:0%
Abilities: Poison Point - Rivalry - Hustle (Hidden Ability)
Base Stats
----------------------
Total: 273
Hp: 46
Attack: 57
Defence: 40
Special Attack: 40
Special Defence: 40
Speed: 50

View File

@ -1,15 +0,0 @@
Name: Popplio
Pokedex Number: 728
Gender Ratio:  ♂:88.14% ♀:11.86%
Abilities: Torrent - Liquid Voice (Hidden Ability)
Base Stats
----------------------
Total: 320
Hp: 50
Attack: 54
Defence: 54
Special Attack: 66
Special Defence: 56
Speed: 40

View File

@ -1 +0,0 @@
Stats currently unavailable :(

View File

@ -32,15 +32,19 @@ begin_url = ["http://serebii.net/pokedex-xy/",
"http://serebii.net/pokedex-rs/", "http://serebii.net/pokedex-rs/",
"http://serebii.net/pokedex-gs/", "http://serebii.net/pokedex-gs/",
"http://serebii.net/pokedex/"] "http://serebii.net/pokedex/"]
for i in begin_url: for i in begin_url:
request1 = requests.get(i) try:
html1 = request1.content request1 = requests.get(i)
soup1 = BeautifulSoup(html1, "html.parser") except OSError:
page_info1 = soup1.get_text() sys.exit(1)
html1 = request1.content
soup1 = BeautifulSoup(html1, "html.parser")
page_info1 = soup1.get_text()
# Pokedex Entries Start At Index 5000 # Pokedex Entries Start At Index 5000
pokemon_index = page_info1.find(pokemon, 5000) pokemon_index = page_info1.find(pokemon, 5000)
if pokemon_index != -1: if pokemon_index != -1:
break break
if pokemon_index == -1: if pokemon_index == -1:
print("You didn't enter a valid pokemon!") print("You didn't enter a valid pokemon!")
@ -58,8 +62,10 @@ for i in begin_url:
page_not_found = bool(soup2.find(string=re.compile("Page Not Found"))) page_not_found = bool(soup2.find(string=re.compile("Page Not Found")))
if page_not_found == False: if page_not_found == False:
break break
if page_not_found: if page_not_found:
print(" Stats currently unavailable :( ") print(" Stats currently unavailable :( ")
sys.exit(1)
######## Get Stats ######## ######## Get Stats ########
base_total = soup2.find(string=re.compile("Base Stats - Total:")) base_total = soup2.find(string=re.compile("Base Stats - Total:"))