From 0e229d8c4058fbbf83a546aed423b7855931bcf9 Mon Sep 17 00:00:00 2001 From: Eric Lay Date: Sat, 22 Apr 2023 17:31:05 -0500 Subject: [PATCH] integrate jq/parse/update functions --- PKGBUILD | 2 + jqPokeTest2 | 8 --- pokeInfo | 124 --------------------------------------- jqPoke => pokeParse | 0 jqPokeTest => pokeUpdate | 4 +- 5 files changed, 5 insertions(+), 133 deletions(-) delete mode 100755 jqPokeTest2 delete mode 100755 pokeInfo rename jqPoke => pokeParse (100%) rename jqPokeTest => pokeUpdate (77%) diff --git a/PKGBUILD b/PKGBUILD index bcc8ee3..77728b9 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -25,5 +25,7 @@ package() { cd "$srcdir/${pkgname:0:-4}" install -Dm666 pokeData/* -t "$pkgdir/usr/share/$pkgname/pokeData" install -Dm666 keybindings-preview -t "$pkgdir/usr/share/$pkgname" + install -Dm755 pokeParse -t "$pkgdir/usr/bin" + install -Dm755 pokeUpdate -t "$pkgdir/usr/bin" install -Dm755 pokedex-dev -t "$pkgdir/usr/bin" } diff --git a/jqPokeTest2 b/jqPokeTest2 deleted file mode 100755 index 712f384..0000000 --- a/jqPokeTest2 +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -block() { - ./jqPoke "$1" > "./pokeData/$1" -} - -export -f block -pokemon-colorscripts -l | sort | parallel --bar -j 200 block diff --git a/pokeInfo b/pokeInfo deleted file mode 100755 index 750a885..0000000 --- a/pokeInfo +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python - -from bs4 import BeautifulSoup -import requests -import sys -import re - -######## Get Pokemon Name ######## -if len(sys.argv) < 2: - pokemon = input("Enter the name of the pokemon to look up: ").title() - -# Two Word Names Like Mime Jr. -elif len(sys.argv) == 3: - pokemon = (sys.argv[1] + " " + sys.argv[2]).title() - -else: - pokemon = sys.argv[1].title() - -if pokemon == "mr-mime": - pokemon = "Mr.Mime" #serebii listed this way - -elif pokemon == "ho-oh": - pokemon = "Ho-oh" #serebii listed this way - -######## Get Pokedex Entry Number ######## -begin_url = ["http://serebii.net/pokedex-xy/", - "http://serebii.net/pokedex-sv/", - "http://serebii.net/pokedex-swsh/", - "http://serebii.net/pokedex-sm/", - "http://serebii.net/pokedex-bw/", - "http://serebii.net/pokedex-dp/", - "http://serebii.net/pokedex-rs/", - "http://serebii.net/pokedex-gs/", - "http://serebii.net/pokedex/"] - -for i in begin_url: - try: - request1 = requests.get(i) - except OSError: - sys.exit(1) - html1 = request1.content - soup1 = BeautifulSoup(html1, "html.parser") - page_info1 = soup1.get_text() - # Pokedex Entries Start At Index 5000 - pokemon_index = page_info1.find(pokemon, 5000) - if pokemon_index != -1: - break - -if pokemon_index == -1: - print("You didn't enter a valid pokemon!") - sys.exit(1) - -pokedex_number = page_info1[pokemon_index-4 : pokemon_index-1] - -######## Get Pokemon Info ######## -for i in begin_url: - try: - full_url = i + pokedex_number + ".shtml" - request2 = requests.get(full_url) - except OSError: - sys.exit(1) - html2 = request2.content - soup2 = BeautifulSoup(html2, "html.parser") - page_info2 = soup2.get_text() - page_not_found = bool(soup2.find(string=re.compile("Page Not Found"))) - if page_not_found == False: - break - -if page_not_found: - print(" Stats currently unavailable :( ") - sys.exit(1) - -######## Get Stats ######## -base_total = soup2.find(string=re.compile("Base Stats - Total:")) -# Only want everything after Total -base_total = str("Total Unavailable") -base_total = base_total[base_total.find("Total"):] -base_stats = soup2.find_all(class_="fooinfo") - -hp = str(base_stats[len(base_stats)-21]) -attack = str(base_stats[len(base_stats)-20]) -defence = str(base_stats[len(base_stats)-19]) -spec_attack = str(base_stats[len(base_stats)-18]) -spec_defence = str(base_stats[len(base_stats)-17]) -speed = str(base_stats[len(base_stats)-16]) - -hp = hp[hp.find(">")+1 : hp.find("/")-1] -attack = attack[attack.find(">")+1 : attack.find("/")-1] -defence = defence[defence.find(">")+1 : defence.find("/")-1] -spec_attack = spec_attack[spec_attack.find(">")+1 : spec_attack.find("/")-1] -spec_defence = spec_defence[spec_defence.find(">")+1 : spec_defence.find("/")-1] -speed = speed[speed.find(">")+1:speed.find("/")-1] - -######## Get Abilities ######## -abilities_index = page_info2.find("Abilities:") -abilities = page_info2[abilities_index:] -end_index = abilities.find("\n") -abilities = abilities[:end_index-1] - -######## Get Gender ######## -gender_index = page_info2.find("GenderType") -gender = page_info2[gender_index:] -end_index = gender.find("\n") -gender = gender[:end_index] -gender = gender[gender.find(" ")+1:] -if "is Genderless" in gender: - gender = "Genderless" - -######## Print everything out ######## -print("") -print("Name: ", pokemon) -print("Pokedex Number: ", pokedex_number) -print("Gender Ratio: ", str(gender)) -print(abilities) -print("") -print("Base Stats") -print("----------------------") -print(base_total) -print("Hp: ", hp) -print("Attack: ", attack) -print("Defence: ", defence) -print("Special Attack: ", spec_attack) -print("Special Defence: ", spec_defence) -print("Speed: ", speed) diff --git a/jqPoke b/pokeParse similarity index 100% rename from jqPoke rename to pokeParse diff --git a/jqPokeTest b/pokeUpdate similarity index 77% rename from jqPokeTest rename to pokeUpdate index f6e6abf..a8d2f7a 100755 --- a/jqPokeTest +++ b/pokeUpdate @@ -1,5 +1,7 @@ #!/bin/bash +DATADIR="/usr/share/fuzzy-pokedex-dev" + declare -i WC WC=$(pokemon-colorscripts -l | wc | awk '{print $1}' ) @@ -7,7 +9,7 @@ declare -i COUNT COUNT="$WC" for POKEMON in $(pokemon-colorscripts -l); do - ./jqPoke "$POKEMON" > "./pokeData/$POKEMON" + pokeParse "$POKEMON" > "$DATADIR/$POKEMON" ((COUNT--)) PCTLEFT="$((COUNT*100/WC))" PCTDONE="$((100-PCTLEFT))"