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.
65 lines
2.0 KiB
65 lines
2.0 KiB
import sqlite3
|
|
from flask import Flask, render_template, jsonify
|
|
|
|
app = Flask(__name__)
|
|
|
|
def load_pokemon_data():
|
|
pokemon_list = []
|
|
|
|
conn = sqlite3.connect('pokemon_database.db')
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('''
|
|
SELECT p.national_dex_number, p.name, pf.form_name, pf.image_path, pf.is_default
|
|
FROM pokemon p
|
|
JOIN pokemon_forms pf ON p.national_dex_number = pf.pokemon_id
|
|
ORDER BY p.national_dex_number, pf.is_default DESC, pf.form_name
|
|
''')
|
|
|
|
for row in cursor.fetchall():
|
|
national_dex_number, name, form_name, image_path, is_default = row
|
|
|
|
pokemon_list.append({
|
|
'ID': national_dex_number,
|
|
'Name': name,
|
|
'Form': form_name,
|
|
'Image': image_path,
|
|
'IsDefault': is_default
|
|
})
|
|
|
|
conn.close()
|
|
return pokemon_list
|
|
|
|
@app.route('/')
|
|
def index():
|
|
pokemon_list = load_pokemon_data()
|
|
# Create a list of lists, each inner list containing up to 30 Pokémon forms
|
|
grouped_pokemon = [pokemon_list[i:i+30] for i in range(0, len(pokemon_list), 30)]
|
|
return render_template('index.html', grouped_pokemon=grouped_pokemon)
|
|
|
|
@app.route('/pokemon/<int:dex_number>')
|
|
def pokemon_details(dex_number):
|
|
conn = sqlite3.connect('pokemon_database.db')
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('''
|
|
SELECT pf.form_name, g.name, l.name, em.name
|
|
FROM form_encounters fe
|
|
JOIN games g ON fe.game_id = g.id
|
|
JOIN locations l ON fe.location_id = l.id
|
|
JOIN encounter_methods em ON fe.encounter_method_id = em.id
|
|
JOIN pokemon_forms pf ON fe.form_id = pf.id
|
|
WHERE pf.pokemon_id = ?
|
|
ORDER BY pf.is_default DESC, pf.form_name, g.generation, g.name, l.name
|
|
''', (dex_number,))
|
|
|
|
encounters = [
|
|
{'form': form, 'game': game, 'location': location, 'method': method}
|
|
for form, game, location, method in cursor.fetchall()
|
|
]
|
|
|
|
conn.close()
|
|
return jsonify(encounters)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|
|
|