- Pokémon Essentials Version
- v21 ➖
Ever wanted to quickly sort your Pokemon by stat, type, ability, name, or base stat total? Then you need my Python Instant Sorting SQL Script!
Simply copypaste the following code into a new text file in your PBS folder, rename it to "Pokemon-SQL-Sorter.py", and run it. This will create a "pokemon_db.db" file, which you can open with "DB Browser (SQL Lite)" or any other SQL program you want. I recommend a free and open source one! Now you can sort through all the Pokemon in your game however you want!
- Populate water sources with Water Pokemon!
- Want to quickly create some Snowboarders and the Ice-type Gym Leader by writing Ice into the Types list (ensuring only Ice-types are displayed) and clicking the Attack column to sort it by highest attack to lowest attack?
- Sort Pokemon by BST to find weak Pokemon to place at your game's start and stronger Pokemon to place at the end/in optional areas!
- Search for a specific Pokemon Type or Type Combination or Name!
- Search for a specific ability! Want to know who in your game has Adaptability or Download or Prankster?
- Make some Hikers and Miners and the Rock-type Gym Leader by writing Rock into the Types list (ensuring only Rock-types are displayed) and clicking the Defense column to sort it by highest defense to lowest defense!
Simply copypaste the following code into a new text file in your PBS folder, rename it to "Pokemon-SQL-Sorter.py", and run it. This will create a "pokemon_db.db" file, which you can open with "DB Browser (SQL Lite)" or any other SQL program you want. I recommend a free and open source one! Now you can sort through all the Pokemon in your game however you want!
Code:
import sqlite3
# Function to create and populate the database
def create_and_populate_database(text_filename, db_filename, table_name):
conn = sqlite3.connect(db_filename)
cursor = conn.cursor()
# Create table
cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (Name TEXT PRIMARY KEY, Types TEXT, HP INTEGER, Attack INTEGER, Defense INTEGER, Speed INTEGER, SpecialAttack INTEGER, SpecialDefense INTEGER, BaseStatTotal INTEGER, Abilities TEXT)")
with open(text_filename, 'r', encoding='utf-8') as file:
lines = file.readlines()
pokemon_data = {}
for line in lines:
line = line.strip()
if line.startswith("[") and "]" in line:
if pokemon_data:
insert_data_into_database(cursor, table_name, pokemon_data)
pokemon_data = {"Name": line[1:-1]}
elif "=" in line:
key, value = map(str.strip, line.split("="))
if key == "Abilities":
abilities = value.split(",")
abilities = [ability.strip() for ability in abilities]
pokemon_data[key] = ', '.join(abilities)
else:
pokemon_data[key] = value
# Insert the last pokemon data into the database
if pokemon_data:
insert_data_into_database(cursor, table_name, pokemon_data)
conn.commit()
conn.close()
# Function to insert data into the database
def insert_data_into_database(cursor, table_name, data):
cursor.execute(f"INSERT INTO {table_name} (Name, Types, HP, Attack, Defense, Speed, SpecialAttack, SpecialDefense, BaseStatTotal, Abilities) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(data["Name"], data.get("Types"), data.get("BaseStats").split(",")[0], data.get("BaseStats").split(",")[1],
data.get("BaseStats").split(",")[2], data.get("BaseStats").split(",")[3], data.get("BaseStats").split(",")[4],
data.get("BaseStats").split(",")[5], calculate_base_stat_total(data), data.get("Abilities")))
def calculate_base_stat_total(data):
return sum(int(data.get("BaseStats").split(",")[i]) for i in range(6))
# Function to retrieve and display sorted Pokémon data
def display_sorted_data(table_name, sort_column):
conn = sqlite3.connect('pokemon_db.db')
cursor = conn.cursor()
if sort_column == "BaseStatTotal":
cursor.execute(f"SELECT * FROM {table_name} ORDER BY {sort_column} DESC")
else:
cursor.execute(f"SELECT * FROM {table_name} ORDER BY {sort_column}")
sorted_data = cursor.fetchall()
for row in sorted_data:
print(row)
conn.close()
def main():
text_filename = 'pokemon.txt'
db_filename = 'pokemon_db.db'
table_name = 'pokemon_table'
create_and_populate_database(text_filename, db_filename, table_name)
print("Database has been populated.")
# Jason Godwyn is the coolest
display_sorted_data(table_name, "BaseStatTotal")
if __name__ == "__main__":
main()
- Credits
- Me, also known as Jason Godwyn.