You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
5.8 KiB
169 lines
5.8 KiB
import sqlite3
|
|
from flask import Flask, render_template, jsonify
|
|
from collections import defaultdict
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
|
|
def load_pokemon_data():
|
|
pokemon_list = []
|
|
|
|
conn = sqlite3.connect('pokemon_forms.db')
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('''
|
|
WITH RECURSIVE EvolutionChain AS (
|
|
SELECT PFIC, from_pfic
|
|
FROM evolution_chains
|
|
UNION ALL
|
|
SELECT ec.PFIC, e.from_pfic
|
|
FROM evolution_chains ec
|
|
JOIN EvolutionChain e ON ec.from_pfic = e.PFIC
|
|
),
|
|
BaseForm AS (
|
|
SELECT PFIC, MIN(from_pfic) AS base_pfic
|
|
FROM EvolutionChain
|
|
GROUP BY PFIC
|
|
),
|
|
EarliestGamePerPokemon AS (
|
|
SELECT e.pfic, MIN(g.generation) as min_generation, g.name as earliest_game
|
|
FROM encounters e
|
|
JOIN games g ON e.game = g.name
|
|
GROUP BY e.pfic
|
|
),
|
|
FirstGameInEarliestGen AS (
|
|
SELECT eg.pfic, MIN(g.id) as first_game_id
|
|
FROM EarliestGamePerPokemon eg
|
|
JOIN games g ON eg.min_generation = g.generation
|
|
GROUP BY eg.pfic
|
|
)
|
|
SELECT
|
|
pf.national_dex, pf.name, pf.form_name, pf.PFIC, pf.generation,
|
|
ps.storable_in_home, eg.earliest_game,
|
|
m.icon_path as mark_icon, m.id as mark_id
|
|
FROM pokemon_forms pf
|
|
JOIN pokemon_storage ps ON pf.PFIC = ps.PFIC
|
|
LEFT JOIN BaseForm bf ON pf.PFIC = bf.PFIC
|
|
LEFT JOIN EarliestGamePerPokemon eg ON COALESCE(bf.base_pfic, pf.PFIC) = eg.pfic
|
|
LEFT JOIN FirstGameInEarliestGen fg ON COALESCE(bf.base_pfic, pf.PFIC) = fg.pfic
|
|
LEFT JOIN games g ON fg.first_game_id = g.id
|
|
LEFT JOIN mark_game_associations mga ON g.id = mga.game_id
|
|
LEFT JOIN marks m ON mga.mark_id = m.id
|
|
WHERE ps.storable_in_home = 1
|
|
ORDER BY pf.PFIC
|
|
''')
|
|
|
|
current_group = []
|
|
current_generation = None
|
|
current_dex_number = None
|
|
pokemon_forms = []
|
|
|
|
for row in cursor.fetchall():
|
|
national_dex, name, form_name, pfic, generation, storable_in_home, earliest_game, mark_icon, mark_id = row
|
|
|
|
pokemon = {
|
|
'ID': national_dex,
|
|
'Name': name,
|
|
'Form': form_name if form_name else "Default",
|
|
'Image': f"images/pokemon/{pfic}.png",
|
|
'IsDefault': form_name is None or form_name == '',
|
|
'Generation': generation,
|
|
'EarliestGame': earliest_game,
|
|
'StorableInHome': storable_in_home,
|
|
'MarkIcon': mark_icon,
|
|
'MarkID': mark_id
|
|
}
|
|
|
|
|
|
|
|
if national_dex != current_dex_number:
|
|
if pokemon_forms:
|
|
for form in pokemon_forms:
|
|
current_group.append(form)
|
|
if len(current_group) == 30:
|
|
pokemon_list.append(current_group)
|
|
current_group = []
|
|
pokemon_forms = []
|
|
current_dex_number = national_dex
|
|
|
|
if form_name is None or form_name == '':
|
|
if current_generation is None or generation != current_generation:
|
|
if current_group:
|
|
while len(current_group) < 30:
|
|
current_group.append(None) # Add empty slots
|
|
pokemon_list.append(current_group)
|
|
current_group = []
|
|
current_generation = generation
|
|
|
|
pokemon_forms.append(pokemon)
|
|
|
|
# Add the last set of forms
|
|
for form in pokemon_forms:
|
|
current_group.append(form)
|
|
if len(current_group) == 30:
|
|
pokemon_list.append(current_group)
|
|
current_group = []
|
|
|
|
# Add any remaining Pokémon
|
|
if current_group:
|
|
while len(current_group) < 30:
|
|
current_group.append(None) # Add empty slots to the last group
|
|
pokemon_list.append(current_group)
|
|
|
|
conn.close()
|
|
return pokemon_list
|
|
|
|
@app.route('/')
|
|
def index():
|
|
pokemon_list = load_pokemon_data()
|
|
return render_template('index.html', grouped_pokemon=pokemon_list)
|
|
|
|
@app.route('/pokemon/<int:dex_number>')
|
|
def pokemon_details(dex_number):
|
|
conn = sqlite3.connect('pokemon_forms.db') # Updated database name
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('''
|
|
SELECT pf.form_name, e.game, e.location, e.day, e.time,
|
|
e.dual_slot, e.static_encounter, e.static_encounter_count,
|
|
e.extra_text, e.stars, e.fishing, e.rods, e.starter
|
|
FROM pokemon_forms pf
|
|
JOIN encounters e ON pf.PFIC = e.pfic
|
|
WHERE pf.national_dex = ?
|
|
ORDER BY pf.form_name, e.game, e.location
|
|
''', (dex_number,))
|
|
|
|
encounters = [
|
|
{
|
|
'form': form,
|
|
'game': game,
|
|
'location': location,
|
|
'day': day,
|
|
'time': time,
|
|
'dual_slot': dual_slot,
|
|
'static_encounter': static_encounter,
|
|
'static_encounter_count': static_encounter_count,
|
|
'extra_text': extra_text,
|
|
'stars': stars,
|
|
'fishing': fishing,
|
|
'rods': rods,
|
|
'starter': starter
|
|
}
|
|
for form, game, location, day, time, dual_slot, static_encounter, static_encounter_count,
|
|
extra_text, stars, fishing, rods, starter in cursor.fetchall()
|
|
]
|
|
|
|
conn.close()
|
|
return jsonify(encounters)
|
|
|
|
if __name__ == '__main__':
|
|
extra_files = ['.']
|
|
extra_dirs = ['./templates/', './static/']
|
|
for extra_dir in extra_dirs:
|
|
for dirname, dirs, files in os.walk(extra_dir):
|
|
for filename in files:
|
|
filename = os.path.join(dirname, filename)
|
|
if os.path.isfile(filename):
|
|
extra_files.append(filename)
|
|
|
|
app.run(debug=True, extra_files=extra_files)
|
|
|