|
|
|
@ -129,6 +129,30 @@ def find_pokemon(name, form=None, threshold=80): |
|
|
|
|
|
|
|
return None |
|
|
|
|
|
|
|
def roman_to_int(s): |
|
|
|
roman_values = { |
|
|
|
'I': 1, |
|
|
|
'V': 5, |
|
|
|
'X': 10, |
|
|
|
'L': 50, |
|
|
|
'C': 100, |
|
|
|
'D': 500, |
|
|
|
'M': 1000 |
|
|
|
} |
|
|
|
|
|
|
|
total = 0 |
|
|
|
prev_value = 0 |
|
|
|
|
|
|
|
for char in reversed(s): |
|
|
|
current_value = roman_values[char] |
|
|
|
if current_value >= prev_value: |
|
|
|
total += current_value |
|
|
|
else: |
|
|
|
total -= current_value |
|
|
|
prev_value = current_value |
|
|
|
|
|
|
|
return total |
|
|
|
|
|
|
|
class Pokemon: |
|
|
|
def __init__(self, name: str, number: int, form: Optional[str] = None): |
|
|
|
self.name = name |
|
|
|
@ -140,6 +164,7 @@ class Pokemon: |
|
|
|
self.encounter_information: Optional[List['EncounterInformation']] = [] |
|
|
|
self.earliest_game: Optional['EncounterInformation'] = None |
|
|
|
self.obtain_method: Optional[str] = None |
|
|
|
self.introduced_in_gen = None |
|
|
|
|
|
|
|
def get_earliest_game_and_method(self): |
|
|
|
if self.evolution_chain: |
|
|
|
@ -485,6 +510,45 @@ def parse_eevee_evolution_chain(table): |
|
|
|
|
|
|
|
return [eevee_stage] |
|
|
|
|
|
|
|
def get_intro_generation(pokemon_name, form, cache): |
|
|
|
page_data = get_pokemon_data_bulbapedia(pokemon_name, cache) |
|
|
|
if not page_data: |
|
|
|
return None |
|
|
|
|
|
|
|
soup = BeautifulSoup(page_data, 'html.parser') |
|
|
|
|
|
|
|
locations_section = soup.find('span', id='Game_locations') |
|
|
|
if not locations_section: |
|
|
|
return None |
|
|
|
|
|
|
|
locations_table = locations_section.find_next('table', class_='roundy') |
|
|
|
if not locations_table: |
|
|
|
return None |
|
|
|
|
|
|
|
generation_tbody = locations_table.find('tbody', recursive=False) |
|
|
|
generation_rows = generation_tbody.find_all('tr', recursive=False) |
|
|
|
for generation_row in generation_rows: |
|
|
|
random_nested_td = generation_row.find('td', recursive=False) |
|
|
|
if not random_nested_td: |
|
|
|
continue |
|
|
|
random_nested_table = random_nested_td.find('table', recursive=False) |
|
|
|
if not random_nested_table: |
|
|
|
continue |
|
|
|
random_nested_tbody = random_nested_table.find('tbody', recursive=False) |
|
|
|
random_nested_rows = random_nested_tbody.find_all('tr', recursive=False) |
|
|
|
|
|
|
|
for nested_row in random_nested_rows: |
|
|
|
test_text = None |
|
|
|
pattern = r"Generation\s+([IVXLCDM]+)" |
|
|
|
match = re.search(pattern, nested_row.get_text(strip=True)) |
|
|
|
if match: |
|
|
|
test_text = match.group(1) # This returns just the Roman numeral |
|
|
|
|
|
|
|
if test_text: |
|
|
|
return roman_to_int(test_text.replace("Generation ", "").strip()) |
|
|
|
|
|
|
|
return None |
|
|
|
|
|
|
|
def get_locations_from_bulbapedia(pokemon_name, form, cache): |
|
|
|
page_data = get_pokemon_data_bulbapedia(pokemon_name, cache) |
|
|
|
if not page_data: |
|
|
|
@ -519,6 +583,8 @@ def get_locations_from_bulbapedia(pokemon_name, form, cache): |
|
|
|
continue |
|
|
|
random_nested_tbody = random_nested_table.find('tbody', recursive=False) |
|
|
|
random_nested_rows = random_nested_tbody.find_all('tr', recursive=False) |
|
|
|
intro_gen = None |
|
|
|
|
|
|
|
for nested_row in random_nested_rows: |
|
|
|
if 'Generation' in nested_row.get_text(strip=True): |
|
|
|
continue |
|
|
|
@ -714,6 +780,7 @@ def determine_earliest_games(cache): |
|
|
|
form_to_find = None |
|
|
|
if pokemon.name in bad_tea_pokemon: |
|
|
|
form_to_find = get_bad_tea_form(pokemon) |
|
|
|
pokemon.introduced_in_gen = get_intro_generation(pokemon.name, form_to_find, cache) |
|
|
|
encounter_data = get_locations_from_bulbapedia(pokemon.name, form_to_find, cache) |
|
|
|
for encounter in encounter_data: |
|
|
|
encounter_information = EncounterInformation(encounter, encounter_data[encounter]) |
|
|
|
@ -748,7 +815,7 @@ def adjust_for_evolution(cache): |
|
|
|
|
|
|
|
def save_to_csv(filename='pokemon_earliest_games.csv'): |
|
|
|
with open(filename, 'w', newline='', encoding='utf-8') as csvfile: |
|
|
|
fieldnames = ['number', 'name', 'earliest_game', 'obtain_method', 'encounter_locations'] |
|
|
|
fieldnames = ['number', 'name', 'introduced_in_gen', 'earliest_game', 'obtain_method', 'encounter_locations'] |
|
|
|
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) |
|
|
|
|
|
|
|
writer.writeheader() |
|
|
|
@ -760,6 +827,7 @@ def save_to_csv(filename='pokemon_earliest_games.csv'): |
|
|
|
writer.writerow({ |
|
|
|
'number': pokemon.number, |
|
|
|
'name': f"{pokemon.name} ({pokemon.form})", |
|
|
|
'introduced_in_gen': pokemon.introduced_in_gen, |
|
|
|
'earliest_game': pokemon.earliest_game.game, |
|
|
|
'obtain_method': pokemon.earliest_game.method, |
|
|
|
'encounter_locations': ' | '.join((str(item) for item in encounter_locations)) |
|
|
|
|