|
|
|
@ -207,31 +207,63 @@ def extract_additional_information(s): |
|
|
|
else: |
|
|
|
return full_text, details |
|
|
|
|
|
|
|
def build_query_string(table_name, criteria): |
|
|
|
conditions = [] |
|
|
|
values = [] |
|
|
|
query = f"SELECT * FROM {table_name} WHERE " |
|
|
|
|
|
|
|
for column, value in criteria.items(): |
|
|
|
if value is None: |
|
|
|
conditions.append(f"({column} IS NULL OR {column} = '')") |
|
|
|
elif value == "": |
|
|
|
conditions.append(f"{column} = ''") |
|
|
|
else: |
|
|
|
conditions.append(f"{column} = ?") |
|
|
|
values.append(value) |
|
|
|
|
|
|
|
return query + " AND ".join(conditions), values |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
insert_query = ''' |
|
|
|
INSERT INTO encounters |
|
|
|
(pfic, game, location, day, time, dual_slot, static_encounter_count, static_encounter, extra_text, stars, rods, fishing, starter) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
|
''' |
|
|
|
|
|
|
|
criteria = { |
|
|
|
"pfic": pfic, |
|
|
|
"game": game, |
|
|
|
"location": location, |
|
|
|
"day": None, |
|
|
|
"time": None, |
|
|
|
"dual_slot": dual_slot, |
|
|
|
"static_encounter": static_encounter, |
|
|
|
"static_encounter_count": static_encounter_count, |
|
|
|
"extra_text": extra_text_str, |
|
|
|
"stars": stars_str, |
|
|
|
"rods": rods_str, |
|
|
|
"fishing": fishing, |
|
|
|
"starter": starter |
|
|
|
} |
|
|
|
|
|
|
|
if len(days) > 0: |
|
|
|
for day in days: |
|
|
|
criteria["day"] = day |
|
|
|
criteria["time"] = None |
|
|
|
query, values = build_query_string("encounters", criteria) |
|
|
|
# Check if an identical record already exists |
|
|
|
cursor.execute(''' |
|
|
|
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, |
|
|
|
cursor.execute(query, values) |
|
|
|
|
|
|
|
encounter = cursor.fetchone() |
|
|
|
|
|
|
|
if encounter == None or encounter[0] == 0: |
|
|
|
cursor.execute(insert_query, (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: |
|
|
|
@ -239,42 +271,32 @@ def save_encounter(conn, pfic, game, location, days, times, dual_slot, static_en |
|
|
|
|
|
|
|
elif len(times) > 0: |
|
|
|
for time in times: |
|
|
|
criteria["day"] = None |
|
|
|
criteria["time"] = time |
|
|
|
query, values = build_query_string("encounters", criteria) |
|
|
|
# Check if an identical record already exists |
|
|
|
cursor.execute(''' |
|
|
|
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)) |
|
|
|
cursor.execute(query, values) |
|
|
|
|
|
|
|
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, |
|
|
|
encounter = cursor.fetchone() |
|
|
|
|
|
|
|
if encounter == None or encounter[0] == 0: |
|
|
|
cursor.execute(insert_query, (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: |
|
|
|
criteria["day"] = None |
|
|
|
criteria["time"] = None |
|
|
|
query, values = build_query_string("encounters", criteria) |
|
|
|
# Check if an identical record already exists |
|
|
|
cursor.execute(''' |
|
|
|
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, |
|
|
|
cursor.execute(query, values) |
|
|
|
|
|
|
|
encounter = cursor.fetchone() |
|
|
|
|
|
|
|
if encounter == None or encounter[0] == 0: |
|
|
|
cursor.execute(insert_query, (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: |
|
|
|
@ -315,6 +337,9 @@ def process_pokemon_for_location_data(pfic, name, form, national_dex, default_fo |
|
|
|
if name == "Alcremie": |
|
|
|
form = None |
|
|
|
|
|
|
|
if name == "Minior": |
|
|
|
form = None |
|
|
|
|
|
|
|
if form and form.lower() == "female": |
|
|
|
form = None |
|
|
|
|
|
|
|
@ -366,6 +391,9 @@ def process_pokemon_for_location_data(pfic, name, form, national_dex, default_fo |
|
|
|
if remaining != "": |
|
|
|
remaining_locations = remaining.replace(" and ", ",").split(",") |
|
|
|
for remaining_location in remaining_locations: |
|
|
|
if remaining_location.strip() == "": |
|
|
|
continue |
|
|
|
|
|
|
|
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__": |
|
|
|
|