Browse Source

Auto Generate a better description of a location

main
Quildra 1 year ago
parent
commit
f9f25f54ea
  1. 31
      Utilities/DatabaseBuilder.py

31
Utilities/DatabaseBuilder.py

@ -105,6 +105,32 @@ def create_tables(conn):
conn.commit() conn.commit()
def tidy_location_name(name):
# Replace '-' with spaces
name = name.replace('-', ' ')
# Remove 'area' from the end if present
name = re.sub(r'\sarea$', '', name, flags=re.IGNORECASE)
# Capitalize the first letter of the first word
name = name.capitalize()
# Check for cardinal directions at the end
cardinal_directions = ['north', 'south', 'east', 'west', 'northeast', 'northwest', 'southeast', 'southwest']
for direction in cardinal_directions:
if name.lower().endswith(f' {direction}'):
# Remove the direction from the end and add it in brackets
name = name[:-len(direction)].strip()
name += f' ({direction.capitalize()})'
break
return name
def generate_location_description(name):
# Generate a simple description based on the name
description = f"A location in the Pokémon world known as {name}."
return description
def load_game_data(conn): def load_game_data(conn):
cursor = conn.cursor() cursor = conn.cursor()
@ -318,11 +344,14 @@ def load_encounter_data(conn):
location, method = location_info.strip().rsplit(' ', 1) location, method = location_info.strip().rsplit(' ', 1)
method = method.strip('()') method = method.strip('()')
# Tidy up the location name and generate a description
description = tidy_location_name(location)
# Insert or get location_id # Insert or get location_id
cursor.execute(''' cursor.execute('''
INSERT OR IGNORE INTO locations (name, description) INSERT OR IGNORE INTO locations (name, description)
VALUES (?, ?) VALUES (?, ?)
''', (location, None)) ''', (location, description))
cursor.execute('SELECT id FROM locations WHERE name = ?', (location,)) cursor.execute('SELECT id FROM locations WHERE name = ?', (location,))
location_id = cursor.fetchone()[0] location_id = cursor.fetchone()[0]

Loading…
Cancel
Save