From 6f6e60f925b87554070609dac33e78ea681e112e Mon Sep 17 00:00:00 2001 From: a_magical_me Date: Mon, 20 Dec 2010 20:58:51 -0800 Subject: [PATCH] Add a script for setting pokemon.order --- scripts/set_pokemon_order.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 scripts/set_pokemon_order.py diff --git a/scripts/set_pokemon_order.py b/scripts/set_pokemon_order.py new file mode 100755 index 0000000..2c80ad1 --- /dev/null +++ b/scripts/set_pokemon_order.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python2 + +import sqlite3 + +conn = sqlite3.connect("pokedex/data/pokedex.sqlite") + +cur = conn.execute( + """select p.id, p.name, pf.name + from pokemon p + join evolution_chains ec on p.evolution_chain_id = ec.id + left join pokemon_forms pf on p.id = pf.unique_pokemon_id + order by ec.id, is_baby = 0, coalesce(pf.form_base_pokemon_id, p.id), + pf."order", pf.name + ;""") + +idmap = [] + +for i, row in enumerate(cur): + idmap.append((1 + i, row[0])) + +conn.executemany( + """update pokemon set "order" = ? where id = ?""", + idmap, +) + +conn.commit() + -- 2.7.4