|
|
@ -24,10 +24,18 @@ class GatherHomeStorageStatus(QRunnable): |
|
|
|
|
|
|
|
|
def gather_home_storage_data(self): |
|
|
def gather_home_storage_data(self): |
|
|
all_pokemon_forms = db.get_list_of_pokemon_forms() |
|
|
all_pokemon_forms = db.get_list_of_pokemon_forms() |
|
|
pokemon_storable_in_home = [] |
|
|
|
|
|
pfics_that_can_go_to_home = [] |
|
|
pfics_that_can_go_to_home = [] |
|
|
|
|
|
pokemon_by_national_dex = {} |
|
|
|
|
|
|
|
|
for region in regions: |
|
|
for region in regions: |
|
|
pokemon_storable_in_home.extend(self.scrape_region_for_pokemon(region)) |
|
|
pokemon_list = self.scrape_region_for_pokemon(region) |
|
|
|
|
|
for pokemon in pokemon_list: |
|
|
|
|
|
national_dex = int(pokemon['number']) |
|
|
|
|
|
if national_dex not in pokemon_by_national_dex: |
|
|
|
|
|
pokemon_by_national_dex[national_dex] = [] |
|
|
|
|
|
pokemon_by_national_dex[national_dex].append(pokemon) |
|
|
|
|
|
|
|
|
|
|
|
default_forms_set = set(default_forms) |
|
|
|
|
|
|
|
|
for pokemon_form in all_pokemon_forms: |
|
|
for pokemon_form in all_pokemon_forms: |
|
|
storable_in_home = False |
|
|
storable_in_home = False |
|
|
@ -35,6 +43,9 @@ class GatherHomeStorageStatus(QRunnable): |
|
|
national_dex = pokemon_form["national_dex"] |
|
|
national_dex = pokemon_form["national_dex"] |
|
|
working_form = pokemon_form["form_name"] |
|
|
working_form = pokemon_form["form_name"] |
|
|
|
|
|
|
|
|
|
|
|
if national_dex not in pokemon_by_national_dex: |
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
if working_form and name in working_form: |
|
|
if working_form and name in working_form: |
|
|
working_form = working_form.replace(name, "").strip() |
|
|
working_form = working_form.replace(name, "").strip() |
|
|
|
|
|
|
|
|
@ -42,7 +53,7 @@ class GatherHomeStorageStatus(QRunnable): |
|
|
if working_form and ("male" in working_form.lower() or "working_form" in working_form.lower()): |
|
|
if working_form and ("male" in working_form.lower() or "working_form" in working_form.lower()): |
|
|
working_form = None |
|
|
working_form = None |
|
|
|
|
|
|
|
|
if name == "Unown" and (working_form != "!" and working_form != "?"): |
|
|
if name == "Unown" and (working_form not in ["!", "?"]): |
|
|
working_form = None |
|
|
working_form = None |
|
|
|
|
|
|
|
|
if name == "Tauros" and working_form == "Combat Breed": |
|
|
if name == "Tauros" and working_form == "Combat Breed": |
|
|
@ -52,35 +63,38 @@ class GatherHomeStorageStatus(QRunnable): |
|
|
if name == "Alcremie": |
|
|
if name == "Alcremie": |
|
|
working_form = None |
|
|
working_form = None |
|
|
|
|
|
|
|
|
pokemon_by_national_dex = get_objects_by_number(pokemon_storable_in_home, f"{national_dex:04d}") |
|
|
for pokemon in pokemon_by_national_dex[national_dex]: |
|
|
for pokemon in pokemon_by_national_dex: |
|
|
|
|
|
if working_form: |
|
|
if working_form: |
|
|
parts = pokemon['name'].split(" ") |
|
|
parts = pokemon['name'].split(" ") |
|
|
if len(parts) > 1 and parts[0] == working_form: |
|
|
if len(parts) > 1 and parts[0] == working_form: |
|
|
storable_in_home = True |
|
|
storable_in_home = True |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
brackets = self.extract_bracketed_text(pokemon['name']) |
|
|
brackets = self.extract_bracketed_text(pokemon['name']) |
|
|
if brackets: |
|
|
if brackets: |
|
|
for bracket in brackets: |
|
|
for bracket in brackets: |
|
|
if name in bracket: |
|
|
if name in bracket: |
|
|
bracket = bracket.replace(name, "").strip() |
|
|
bracket = bracket.replace(name, "").strip() |
|
|
if compare_pokemon_forms(working_form, bracket): |
|
|
if compare_pokemon_forms(working_form, bracket): |
|
|
storable_in_home = True |
|
|
storable_in_home = True |
|
|
break |
|
|
break |
|
|
if storable_in_home == False and working_form and working_form in default_forms: |
|
|
|
|
|
|
|
|
if not storable_in_home and working_form in default_forms_set: |
|
|
working_form = None |
|
|
working_form = None |
|
|
|
|
|
|
|
|
if working_form == None and name.lower() in pokemon['name'].lower(): |
|
|
if working_form == None and name.lower() in pokemon['name'].lower(): |
|
|
storable_in_home = True |
|
|
storable_in_home = True |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
if storable_in_home: |
|
|
if storable_in_home: |
|
|
pfics_that_can_go_to_home.append(pokemon_form["pfic"]) |
|
|
pfics_that_can_go_to_home.append(pokemon_form["pfic"]) |
|
|
|
|
|
|
|
|
return pfics_that_can_go_to_home |
|
|
return pfics_that_can_go_to_home |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def scrape_region_for_pokemon(self, region): |
|
|
def scrape_region_for_pokemon(self, region): |
|
|
cached_entry = cache.get(f"home_{region}") |
|
|
cached_entry = cache.get(f"home_{region}") |
|
|
if cached_entry != None: |
|
|
if cached_entry is not None: |
|
|
return cached_entry |
|
|
return cached_entry |
|
|
|
|
|
|
|
|
url = f"{self.base_url}{region}pokemon.shtml" |
|
|
url = f"{self.base_url}{region}pokemon.shtml" |
|
|
@ -90,7 +104,7 @@ class GatherHomeStorageStatus(QRunnable): |
|
|
|
|
|
|
|
|
soup = BeautifulSoup(response, 'html.parser') |
|
|
soup = BeautifulSoup(response, 'html.parser') |
|
|
table = soup.find('table', class_='dextable') |
|
|
table = soup.find('table', class_='dextable') |
|
|
if table == None: |
|
|
if table is None: |
|
|
return [] |
|
|
return [] |
|
|
|
|
|
|
|
|
pokemon_list = [] |
|
|
pokemon_list = [] |
|
|
|