|
|
|
@ -34,109 +34,119 @@ class GatherEvolutions(QRunnable): |
|
|
|
evolutions = {} |
|
|
|
|
|
|
|
for pokemon_form in all_pokemon_forms: |
|
|
|
print(f"Processing {get_display_name(pokemon_form)}'s evolutions") |
|
|
|
pokemon_name = pokemon_form["name"] |
|
|
|
form = get_form_name(pokemon_form) |
|
|
|
|
|
|
|
if pokemon_form["form_name"] and any(s in pokemon_form["form_name"] for s in non_evolution_forms): |
|
|
|
|
|
|
|
evolution_tree = self.gather_evolution_tree(pokemon_form, force_refresh) |
|
|
|
if not evolution_tree: |
|
|
|
continue |
|
|
|
|
|
|
|
cache_record_name = f"chain_{pokemon_name}_{form}" |
|
|
|
if force_refresh: |
|
|
|
cache.purge(cache_record_name) |
|
|
|
|
|
|
|
cached_entry = cache.get(cache_record_name) |
|
|
|
if cached_entry != None: |
|
|
|
evolutions = evolutions | cached_entry |
|
|
|
continue |
|
|
|
|
|
|
|
#form = get_form_name(pokemon_form, not pokemon_form["gender_relevant"]) |
|
|
|
search_form = form |
|
|
|
if search_form and pokemon_name in search_form: |
|
|
|
search_form = search_form.replace(pokemon_name, "").strip() |
|
|
|
|
|
|
|
gender = None |
|
|
|
search_form = get_form_name(pokemon_form) |
|
|
|
if search_form and "male" in search_form.lower(): |
|
|
|
if "female" in search_form.lower(): |
|
|
|
search_form = search_form.replace("Female", "").replace("female", "").strip() |
|
|
|
gender = "Female" |
|
|
|
else: |
|
|
|
search_form = search_form.replace("Male", "").replace("male", "").strip() |
|
|
|
gender = "Male" |
|
|
|
|
|
|
|
if search_form == "": |
|
|
|
search_form = None |
|
|
|
cacheable_container = {} |
|
|
|
self.traverse_and_store(evolution_tree, cacheable_container, gender) |
|
|
|
|
|
|
|
if pokemon_name == "Flabébé": |
|
|
|
# Bulbapedia doesn't detail out Flabébé's evolution chain fully. as its exactly the same for each form, but the coloured form remains constant |
|
|
|
# through the evolution line, Red->Red->Red, Yellow->Yellow->Yellow etc. |
|
|
|
search_form = None |
|
|
|
evolutions = evolutions | cacheable_container |
|
|
|
|
|
|
|
url = f"https://bulbapedia.bulbagarden.net/wiki/{pokemon_name}_(Pokémon)" |
|
|
|
page_data = cache.fetch_url(url) |
|
|
|
if not page_data: |
|
|
|
continue |
|
|
|
print(self.evolution_methods) |
|
|
|
return evolutions |
|
|
|
|
|
|
|
def gather_evolution_tree(self, pokemon_form, force_refresh = False): |
|
|
|
print(f"Processing {get_display_name(pokemon_form)}'s evolutions") |
|
|
|
pokemon_name = pokemon_form["name"] |
|
|
|
form = get_form_name(pokemon_form) |
|
|
|
|
|
|
|
soup = BeautifulSoup(page_data, 'html.parser') |
|
|
|
evolution_section = soup.find('span', id='Evolution_data') |
|
|
|
if not evolution_section: |
|
|
|
continue |
|
|
|
if pokemon_form["form_name"] and any(s in pokemon_form["form_name"] for s in non_evolution_forms): |
|
|
|
return None |
|
|
|
|
|
|
|
evolution_table = None |
|
|
|
evolution_table = evolution_section.parent.find_next('table') |
|
|
|
if form: |
|
|
|
form_without_form = form.replace('Form', '').replace('form', '').strip() |
|
|
|
form_without_form = self.strip_gender_from_form(form_without_form) |
|
|
|
for tag in evolution_section.parent.find_next_siblings(): |
|
|
|
if tag.name == 'h4' and form_without_form in tag.get_text(strip=True): |
|
|
|
evolution_table = tag.find_next('table') |
|
|
|
break |
|
|
|
if tag.name == 'h3': |
|
|
|
break |
|
|
|
if not evolution_table: |
|
|
|
continue |
|
|
|
|
|
|
|
evolution_tree = None |
|
|
|
if pokemon_name == "Eevee": |
|
|
|
evolution_tree = self.parse_eevee_evolution_chain(evolution_table, pokemon_form) |
|
|
|
cache_record_name = f"chain_{pokemon_name}_{form}" |
|
|
|
if force_refresh: |
|
|
|
cache.purge(cache_record_name) |
|
|
|
|
|
|
|
cached_entry = cache.get(cache_record_name) |
|
|
|
if cached_entry != None: |
|
|
|
return cached_entry |
|
|
|
search_form = form |
|
|
|
if search_form and pokemon_name in search_form: |
|
|
|
search_form = search_form.replace(pokemon_name, "").strip() |
|
|
|
|
|
|
|
if search_form and "male" in search_form.lower(): |
|
|
|
if "female" in search_form.lower(): |
|
|
|
search_form = search_form.replace("Female", "").replace("female", "").strip() |
|
|
|
else: |
|
|
|
evolution_tree = self.parse_evolution_chain(evolution_table, pokemon_form) |
|
|
|
|
|
|
|
if evolution_tree["pokemon"] == "Milcery": |
|
|
|
evolution_tree["evolves_to"] = [] |
|
|
|
for alcremie_form in alcremie_forms: |
|
|
|
node = { |
|
|
|
"pokemon": "Alcremie", |
|
|
|
"form": alcremie_form, |
|
|
|
"requirement": None, |
|
|
|
"method": "Complicated", |
|
|
|
"evolves_to": [], |
|
|
|
"stage": 1 |
|
|
|
} |
|
|
|
evolution_tree["evolves_to"].append(node) |
|
|
|
|
|
|
|
if evolution_tree["pokemon"] == "Flabébé": |
|
|
|
def fix_form(node, new_form): |
|
|
|
node["form"] = new_form |
|
|
|
for next in node["evolves_to"]: |
|
|
|
fix_form(next, new_form) |
|
|
|
|
|
|
|
flower_form = get_form_name(pokemon_form) |
|
|
|
if "female" in flower_form.lower(): |
|
|
|
flower_form = flower_form.replace("Female", "").replace("female", "").strip() |
|
|
|
else: |
|
|
|
flower_form = flower_form.replace("Male", "").replace("male", "").strip() |
|
|
|
fix_form(evolution_tree, flower_form) |
|
|
|
search_form = search_form.replace("Male", "").replace("male", "").strip() |
|
|
|
|
|
|
|
cacheable_container = {} |
|
|
|
if evolution_tree: |
|
|
|
self.traverse_and_store(evolution_tree, cacheable_container, gender) |
|
|
|
if search_form == "": |
|
|
|
search_form = None |
|
|
|
|
|
|
|
cache.set(cache_record_name, cacheable_container) |
|
|
|
evolutions = evolutions | cacheable_container |
|
|
|
if pokemon_name == "Flabébé": |
|
|
|
# Bulbapedia doesn't detail out Flabébé's evolution chain fully. as its exactly the same for each form, but the coloured form remains constant |
|
|
|
# through the evolution line, Red->Red->Red, Yellow->Yellow->Yellow etc. |
|
|
|
search_form = None |
|
|
|
|
|
|
|
print(self.evolution_methods) |
|
|
|
return evolutions |
|
|
|
url = f"https://bulbapedia.bulbagarden.net/wiki/{pokemon_name}_(Pokémon)" |
|
|
|
page_data = cache.fetch_url(url) |
|
|
|
if not page_data: |
|
|
|
return None |
|
|
|
|
|
|
|
soup = BeautifulSoup(page_data, 'html.parser') |
|
|
|
evolution_section = soup.find('span', id='Evolution_data') |
|
|
|
if not evolution_section: |
|
|
|
return None |
|
|
|
|
|
|
|
evolution_table = None |
|
|
|
evolution_table = evolution_section.parent.find_next('table') |
|
|
|
if form: |
|
|
|
form_without_form = form.replace('Form', '').replace('form', '').strip() |
|
|
|
form_without_form = self.strip_gender_from_form(form_without_form) |
|
|
|
for tag in evolution_section.parent.find_next_siblings(): |
|
|
|
if tag.name == 'h4' and form_without_form in tag.get_text(strip=True): |
|
|
|
evolution_table = tag.find_next('table') |
|
|
|
break |
|
|
|
if tag.name == 'h3': |
|
|
|
break |
|
|
|
if not evolution_table: |
|
|
|
return None |
|
|
|
|
|
|
|
evolution_tree = None |
|
|
|
if pokemon_name == "Eevee": |
|
|
|
evolution_tree = self.parse_eevee_evolution_chain(evolution_table, pokemon_form) |
|
|
|
else: |
|
|
|
evolution_tree = self.parse_evolution_chain(evolution_table, pokemon_form, force_refresh) |
|
|
|
|
|
|
|
if evolution_tree["pokemon"] == "Milcery": |
|
|
|
evolution_tree["evolves_to"] = [] |
|
|
|
for alcremie_form in alcremie_forms: |
|
|
|
node = { |
|
|
|
"pokemon": "Alcremie", |
|
|
|
"form": alcremie_form, |
|
|
|
"requirement": None, |
|
|
|
"method": "Complicated", |
|
|
|
"evolves_to": [], |
|
|
|
"stage": 1 |
|
|
|
} |
|
|
|
evolution_tree["evolves_to"].append(node) |
|
|
|
|
|
|
|
if evolution_tree["pokemon"] == "Flabébé": |
|
|
|
def fix_form(node, new_form): |
|
|
|
node["form"] = new_form |
|
|
|
for next in node["evolves_to"]: |
|
|
|
fix_form(next, new_form) |
|
|
|
|
|
|
|
flower_form = get_form_name(pokemon_form) |
|
|
|
if "female" in flower_form.lower(): |
|
|
|
flower_form = flower_form.replace("Female", "").replace("female", "").strip() |
|
|
|
else: |
|
|
|
flower_form = flower_form.replace("Male", "").replace("male", "").strip() |
|
|
|
fix_form(evolution_tree, flower_form) |
|
|
|
|
|
|
|
cache.set(cache_record_name, evolution_tree) |
|
|
|
|
|
|
|
return evolution_tree |
|
|
|
|
|
|
|
def traverse_and_store(self, node, evolutions, gender): |
|
|
|
"""Helper function to traverse evolution tree and store evolutions.""" |
|
|
|
@ -180,8 +190,11 @@ class GatherEvolutions(QRunnable): |
|
|
|
evolution_form = self.extract_evolution_form(td, pokemon_name) |
|
|
|
stage = self.extract_stage_form(td).replace("Evolution", "").replace("evolution", "").strip() |
|
|
|
numberical_stage = -1 |
|
|
|
is_baby = False |
|
|
|
if stage == "Unevolved" or stage == "Baby form": |
|
|
|
numberical_stage = 0 |
|
|
|
if stage == "Baby form": |
|
|
|
is_baby = True |
|
|
|
elif stage == "Castoff": |
|
|
|
numberical_stage = 1 |
|
|
|
else: |
|
|
|
@ -192,7 +205,8 @@ class GatherEvolutions(QRunnable): |
|
|
|
"requirement": None, |
|
|
|
"method": None, |
|
|
|
"evolves_to": [], |
|
|
|
"stage": numberical_stage |
|
|
|
"stage": numberical_stage, |
|
|
|
"is_baby": is_baby |
|
|
|
} |
|
|
|
|
|
|
|
# Parse main evolution chain |
|
|
|
@ -315,7 +329,8 @@ class GatherEvolutions(QRunnable): |
|
|
|
"pokemon": pokemon_name, |
|
|
|
"form": None, |
|
|
|
"method": None, |
|
|
|
"evolves_to": [] |
|
|
|
"evolves_to": [], |
|
|
|
"is_baby": False |
|
|
|
} |
|
|
|
|
|
|
|
rows = tbody.find_all('tr', recursive=False) |
|
|
|
|