|
|
|
@ -1,7 +1,12 @@ |
|
|
|
import os |
|
|
|
import sys |
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
|
|
|
|
|
|
import json |
|
|
|
import sqlite3 |
|
|
|
from cache_manager import CacheManager |
|
|
|
from DetermineOriginGame import get_locations_from_bulbapedia |
|
|
|
from DataGatherers.cache_manager import CacheManager |
|
|
|
from DataGatherers.DetermineOriginGame import get_locations_from_bulbapedia |
|
|
|
from bs4 import BeautifulSoup, Tag |
|
|
|
import re |
|
|
|
import time |
|
|
|
@ -204,26 +209,77 @@ def extract_additional_information(s): |
|
|
|
|
|
|
|
def save_encounter(conn, pfic, game, location, days, times, dual_slot, static_encounter, static_encounter_count, extra_text, stars, rods, fishing, starter): |
|
|
|
cursor = conn.cursor() |
|
|
|
|
|
|
|
# Convert lists to strings for comparison, except days and times |
|
|
|
extra_text_str = ' '.join(extra_text) if extra_text else None |
|
|
|
stars_str = ','.join(sorted(stars)) if stars else None |
|
|
|
rods_str = ','.join(sorted(rods)) if rods else None |
|
|
|
|
|
|
|
if len(days) > 0: |
|
|
|
for day in days: |
|
|
|
# Check if an identical record already exists |
|
|
|
cursor.execute(''' |
|
|
|
INSERT OR REPLACE INTO encounters |
|
|
|
(pfic, game, location, day, time, dual_slot, static_encounter_count, static_encounter, extra_text, stars, rods, fishing, starter) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
|
''', (pfic, game, location, day, None, dual_slot, static_encounter_count, static_encounter, ' '.join(extra_text), ','.join(stars), ','.join(rods), fishing, starter)) |
|
|
|
SELECT COUNT(*) FROM encounters |
|
|
|
WHERE pfic = ? AND game = ? AND location = ? AND day = ? AND time IS NULL |
|
|
|
AND dual_slot = ? AND static_encounter = ? AND static_encounter_count = ? |
|
|
|
AND extra_text = ? AND stars = ? AND rods = ? AND fishing = ? AND starter = ? |
|
|
|
''', (pfic, game, location, day, dual_slot, static_encounter, |
|
|
|
static_encounter_count, extra_text_str, stars_str, rods_str, fishing, starter)) |
|
|
|
|
|
|
|
if cursor.fetchone()[0] == 0: |
|
|
|
cursor.execute(''' |
|
|
|
INSERT INTO encounters |
|
|
|
(pfic, game, location, day, time, dual_slot, static_encounter_count, static_encounter, extra_text, stars, rods, fishing, starter) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
|
''', (pfic, game, location, day, None, dual_slot, static_encounter_count, |
|
|
|
static_encounter, extra_text_str, stars_str, rods_str, fishing, starter)) |
|
|
|
print(f"New encounter added for {pfic} in {game} at {location} on {day}") |
|
|
|
else: |
|
|
|
print(f"Identical encounter already exists for {pfic} in {game} at {location} on {day}") |
|
|
|
|
|
|
|
elif len(times) > 0: |
|
|
|
for time in times: |
|
|
|
# Check if an identical record already exists |
|
|
|
cursor.execute(''' |
|
|
|
INSERT OR REPLACE INTO encounters |
|
|
|
(pfic, game, location, day, time, dual_slot, static_encounter_count, static_encounter, extra_text, stars, rods, fishing, starter) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
|
''', (pfic, game, location, None, time, dual_slot, static_encounter_count, static_encounter, ' '.join(extra_text), ','.join(stars), ','.join(rods), fishing, starter)) |
|
|
|
SELECT COUNT(*) FROM encounters |
|
|
|
WHERE pfic = ? AND game = ? AND location = ? AND day IS NULL AND time = ? |
|
|
|
AND dual_slot = ? AND static_encounter = ? AND static_encounter_count = ? |
|
|
|
AND extra_text = ? AND stars = ? AND rods = ? AND fishing = ? AND starter = ? |
|
|
|
''', (pfic, game, location, time, dual_slot, static_encounter, |
|
|
|
static_encounter_count, extra_text_str, stars_str, rods_str, fishing, starter)) |
|
|
|
|
|
|
|
if cursor.fetchone()[0] == 0: |
|
|
|
cursor.execute(''' |
|
|
|
INSERT INTO encounters |
|
|
|
(pfic, game, location, day, time, dual_slot, static_encounter_count, static_encounter, extra_text, stars, rods, fishing, starter) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
|
''', (pfic, game, location, None, time, dual_slot, static_encounter_count, |
|
|
|
static_encounter, extra_text_str, stars_str, rods_str, fishing, starter)) |
|
|
|
print(f"New encounter added for {pfic} in {game} at {location} at {time}") |
|
|
|
else: |
|
|
|
print(f"Identical encounter already exists for {pfic} in {game} at {location} at {time}") |
|
|
|
|
|
|
|
else: |
|
|
|
# Check if an identical record already exists |
|
|
|
cursor.execute(''' |
|
|
|
INSERT OR REPLACE INTO encounters |
|
|
|
SELECT COUNT(*) FROM encounters |
|
|
|
WHERE pfic = ? AND game = ? AND location = ? AND day IS NULL AND time IS NULL |
|
|
|
AND dual_slot = ? AND static_encounter = ? AND static_encounter_count = ? |
|
|
|
AND extra_text = ? AND stars = ? AND rods = ? AND fishing = ? AND starter = ? |
|
|
|
''', (pfic, game, location, dual_slot, static_encounter, |
|
|
|
static_encounter_count, extra_text_str, stars_str, rods_str, fishing, starter)) |
|
|
|
thing = cursor.fetchone() |
|
|
|
if thing[0] == 0: |
|
|
|
cursor.execute(''' |
|
|
|
INSERT INTO encounters |
|
|
|
(pfic, game, location, day, time, dual_slot, static_encounter_count, static_encounter, extra_text, stars, rods, fishing, starter) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
|
''', (pfic, game, location, None, None, dual_slot, static_encounter_count, static_encounter, ' '.join(extra_text), ','.join(stars), ','.join(rods), fishing, starter)) |
|
|
|
''', (pfic, game, location, None, None, dual_slot, static_encounter_count, |
|
|
|
static_encounter, extra_text_str, stars_str, rods_str, fishing, starter)) |
|
|
|
print(f"New encounter added for {pfic} in {game} at {location}") |
|
|
|
else: |
|
|
|
print(f"Identical encounter already exists for {pfic} in {game} at {location}") |
|
|
|
|
|
|
|
conn.commit() |
|
|
|
|
|
|
|
def compare_forms(a, b): |
|
|
|
@ -241,6 +297,77 @@ def compare_forms(a, b): |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
def process_pokemon_for_location_data(pfic, name, form, national_dex, default_forms, cache, conn): |
|
|
|
print(f"Processing {name} {form if form else ''}") |
|
|
|
|
|
|
|
if form and name in form: |
|
|
|
form = form.replace(name, "").strip() |
|
|
|
|
|
|
|
if form and form in default_forms: |
|
|
|
form = None |
|
|
|
|
|
|
|
if name == "Unown" and (form != "!" and form != "?"): |
|
|
|
form = None |
|
|
|
|
|
|
|
if name == "Tauros" and form == "Combat Breed": |
|
|
|
form = "Paldean Form" |
|
|
|
|
|
|
|
if name == "Alcremie": |
|
|
|
form = None |
|
|
|
|
|
|
|
if form and form.lower() == "female": |
|
|
|
form = None |
|
|
|
|
|
|
|
search_form = form |
|
|
|
|
|
|
|
encounters_to_ignore = ["trade", "time capsule", "unobtainable", "evolve", "tradeversion", "poké transfer", "friend safari", "unavailable", "pokémon home"] |
|
|
|
|
|
|
|
encounter_data = get_locations_from_bulbapedia(name, search_form, cache, default_forms) |
|
|
|
if encounter_data == None: |
|
|
|
return |
|
|
|
|
|
|
|
for encounter in encounter_data: |
|
|
|
if len(encounter_data[encounter]) == 0: |
|
|
|
return |
|
|
|
|
|
|
|
print_encounter = True |
|
|
|
|
|
|
|
for location in encounter_data[encounter]: |
|
|
|
if location == "": |
|
|
|
return |
|
|
|
test_location = location["location"].strip().lower() |
|
|
|
|
|
|
|
ignore_location = False |
|
|
|
for ignore in encounters_to_ignore: |
|
|
|
if ignore in test_location: |
|
|
|
ignore_location = True |
|
|
|
break |
|
|
|
|
|
|
|
if ignore_location: |
|
|
|
return |
|
|
|
|
|
|
|
if print_encounter: |
|
|
|
print(f"Found in {encounter}:") |
|
|
|
print_encounter = False |
|
|
|
|
|
|
|
remaining, details = extract_additional_information(location["tag"]) |
|
|
|
routes, remaining = extract_routes(remaining) |
|
|
|
print(f"Routes: {routes}") |
|
|
|
print(f"Remaining: {remaining.strip()}") |
|
|
|
print(f"Details: {details}") |
|
|
|
|
|
|
|
if len(details["times"]) > 0: |
|
|
|
print("Stupid Data") |
|
|
|
|
|
|
|
for route in routes: |
|
|
|
route_name = f"Route {route}" |
|
|
|
save_encounter(conn, pfic, encounter, route_name, details["days"], details["times"], details["dual_slot"], details["static_encounter"], details["static_encounter_count"], details["extra_text"], details["stars"], details["Rods"], details["Fishing"], details["starter"] ) |
|
|
|
|
|
|
|
if remaining != "": |
|
|
|
remaining_locations = remaining.replace(" and ", ",").split(",") |
|
|
|
for remaining_location in remaining_locations: |
|
|
|
save_encounter(conn, pfic, encounter, remaining_location.strip(), details["days"], details["times"], details["dual_slot"], details["static_encounter"], details["static_encounter_count"], details["extra_text"], details["stars"], details["Rods"], details["Fishing"], details["starter"] ) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
cache = CacheManager() |
|
|
|
|
|
|
|
@ -260,76 +387,6 @@ if __name__ == "__main__": |
|
|
|
default_forms = [] |
|
|
|
|
|
|
|
for pfic, name, form, national_dex in pokemon_forms: |
|
|
|
print(f"Processing {name} {form if form else ''}") |
|
|
|
|
|
|
|
if form and name in form: |
|
|
|
form = form.replace(name, "").strip() |
|
|
|
|
|
|
|
if form and form in default_forms: |
|
|
|
form = None |
|
|
|
|
|
|
|
if name == "Unown" and (form != "!" and form != "?"): |
|
|
|
form = None |
|
|
|
|
|
|
|
if name == "Tauros" and form == "Combat Breed": |
|
|
|
form = "Paldean Form" |
|
|
|
|
|
|
|
if name == "Alcremie": |
|
|
|
form = None |
|
|
|
|
|
|
|
if form and form.lower() == "female": |
|
|
|
form = None |
|
|
|
|
|
|
|
search_form = form |
|
|
|
# unrecognized_forms = ["Unown", "Zacian", "Zamazenta"] |
|
|
|
# if name in unrecognized_forms: |
|
|
|
# search_form = None |
|
|
|
|
|
|
|
encounters_to_ignore = ["trade", "time capsule", "unobtainable", "evolve", "tradeversion", "poké transfer", "friend safari", "unavailable", "pokémon home"] |
|
|
|
|
|
|
|
encounter_data = get_locations_from_bulbapedia(name, search_form, cache, default_forms) |
|
|
|
if encounter_data == None: |
|
|
|
continue |
|
|
|
|
|
|
|
for encounter in encounter_data: |
|
|
|
if len(encounter_data[encounter]) == 0: |
|
|
|
continue |
|
|
|
|
|
|
|
print_encounter = True |
|
|
|
|
|
|
|
for location in encounter_data[encounter]: |
|
|
|
if location == "": |
|
|
|
continue |
|
|
|
test_location = location["location"].strip().lower() |
|
|
|
|
|
|
|
ignore_location = False |
|
|
|
for ignore in encounters_to_ignore: |
|
|
|
if ignore in test_location: |
|
|
|
ignore_location = True |
|
|
|
break |
|
|
|
|
|
|
|
if ignore_location: |
|
|
|
continue |
|
|
|
|
|
|
|
if print_encounter: |
|
|
|
print(f"Found in {encounter}:") |
|
|
|
print_encounter = False |
|
|
|
|
|
|
|
remaining, details = extract_additional_information(location["tag"]) |
|
|
|
routes, remaining = extract_routes(remaining) |
|
|
|
print(f"Routes: {routes}") |
|
|
|
print(f"Remaining: {remaining.strip()}") |
|
|
|
print(f"Details: {details}") |
|
|
|
|
|
|
|
if len(details["times"]) > 0: |
|
|
|
print("Stupid Data") |
|
|
|
|
|
|
|
for route in routes: |
|
|
|
route_name = f"Route {route}" |
|
|
|
save_encounter(conn, pfic, encounter, route_name, details["days"], details["times"], details["dual_slot"], details["static_encounter"], details["static_encounter_count"], details["extra_text"], details["stars"], details["Rods"], details["Fishing"], details["starter"] ) |
|
|
|
|
|
|
|
if remaining != "": |
|
|
|
remaining_locations = remaining.replace(" and ", ",").split(",") |
|
|
|
for remaining_location in remaining_locations: |
|
|
|
save_encounter(conn, pfic, encounter, remaining_location.strip(), details["days"], details["times"], details["dual_slot"], details["static_encounter"], details["static_encounter_count"], details["extra_text"], details["stars"], details["Rods"], details["Fishing"], details["starter"] ) |
|
|
|
process_pokemon_for_location_data(pfic, name, form, national_dex, default_forms, cache, conn) |
|
|
|
|
|
|
|
conn.close() |
|
|
|
|