Merge pull request #1 from encukou/xd-tutor

XD/Colosseum tutors
This commit is contained in:
Eevee 2011-11-01 20:40:04 -07:00
commit 936f8f87e7
6 changed files with 10427 additions and 23 deletions

View file

@ -3,7 +3,7 @@
for you to fiddle with it, then convert back to csv and replace the original
file.
Run me as: $0 some_file.csv
Run me as: $0 some_file.csv [other_file.csv ...]
The editor used is $EDITOR, of course.
@ -17,6 +17,7 @@ import os
import subprocess
import sys
import tempfile
import shlex
try:
import yaml
@ -47,20 +48,37 @@ yaml.add_representer(
)
### Do actual work!
infilename, = sys.argv[1:]
infilenames = sys.argv[1:]
data = []
with open(infilename) as infile:
reader = csv.reader(infile, lineterminator='\n')
column_names = [unicode(column) for column in next(reader)]
all_data = []
for infilename in infilenames:
data = []
with open(infilename) as infile:
reader = csv.reader(infile, lineterminator='\n')
column_names = [unicode(column) for column in next(reader)]
# Read data...
for row in reader:
datum = odict()
for col, value in zip(column_names, row):
datum[col] = value.decode('utf-8')
# Read data...
for row in reader:
datum = odict()
for col, value in zip(column_names, row):
# Skip empty values
if value:
datum[col] = value.decode('utf-8')
try:
# Numbers to numbers
if unicode(int(value)) == value:
datum[col] = int(value)
except ValueError:
pass
data.append(datum)
data.append(datum)
file_info = odict((
('name', infilename),
('column_names', column_names),
('rows', data),
))
all_data.append(file_info)
# Monkeypatch yaml to use > syntax for multiline text; easier to edit
@ -76,7 +94,7 @@ Emitter.choose_scalar_style = new_choose_scalar_style
# Write to a tempfile
with tempfile.NamedTemporaryFile(suffix='.yml') as tmp:
yaml.safe_dump(data, tmp,
yaml.safe_dump(all_data, tmp,
default_flow_style=False,
allow_unicode=True,
indent=4,
@ -85,17 +103,21 @@ with tempfile.NamedTemporaryFile(suffix='.yml') as tmp:
error_line = '' # used on errors
while True:
args = [os.environ['EDITOR'], tmp.name]
if 'vim' in os.environ['EDITOR']:
editor = shlex.split(os.environ['EDITOR'])
args = editor + [tmp.name]
if 'vim' in editor[0]:
# vim has an arg for jumping to a line:
args.append("+{0}".format(error_line))
elif 'kate' in editor[0]:
# so does kate!
args.append("-l {0}".format(error_line))
# Run the user's editor and wait for it to close
subprocess.Popen(args).wait()
tmp.seek(0)
try:
new_data = yaml.safe_load(tmp)
all_new_data = yaml.safe_load(tmp)
break
except yaml.YAMLError as e:
if hasattr(e, 'problem_mark'):
@ -111,11 +133,15 @@ with tempfile.NamedTemporaryFile(suffix='.yml') as tmp:
print "Press Enter to try again, or I guess ctrl-c to bail."
raw_input()
with open(infilename, 'wb') as outfile:
writer = csv.writer(outfile, lineterminator='\n')
writer.writerow([ column.encode('utf8') for column in column_names ])
for dct in all_new_data:
filename = dct['name']
new_data = dct['rows']
column_names = dct['column_names']
with open(filename, 'wb') as outfile:
writer = csv.writer(outfile, lineterminator='\n')
writer.writerow([ column.encode('utf8') for column in column_names ])
for datum in new_data:
writer.writerow([
datum[column].encode('utf8') for column in column_names
])
for datum in new_data:
writer.writerow([
unicode(datum.get(column, '')).encode('utf-8') for column in column_names
])

File diff suppressed because it is too large Load diff

View file

@ -10,3 +10,5 @@ id,generation_id,pokedex_id
9,4,6
10,4,7
11,5,8
12,3,4
13,3,4

1 id generation_id pokedex_id
10 9 4 6
11 10 4 7
12 11 5 8
13 12 3 4
14 13 3 4

View file

@ -17,3 +17,5 @@ version_id,local_language_id,name
16,9,SoulSilver
17,9,Black
18,9,White
19,9,Colosseum
20,9,XD

1 version_id local_language_id name
17 16 9 SoulSilver
18 17 9 Black
19 18 9 White
20 19 9 Colosseum
21 20 9 XD

View file

@ -17,3 +17,5 @@ id,version_group_id,identifier
16,10,soulsilver
17,11,black
18,11,white
19,12,colosseum
20,13,xd

1 id version_group_id identifier
17 16 10 soulsilver
18 17 11 black
19 18 11 white
20 19 12 colosseum
21 20 13 xd

121
scripts/xd-tutors.py Normal file
View file

@ -0,0 +1,121 @@
# Encoding: UTF-8
"""Add XD tutors to the database
This is an unmaintained one-shot script, only included in the repo for reference.
"""
from pokedex.db import connect, tables, util
session = connect()
emerald = util.get(session, tables.Version, 'emerald')
fire_red = util.get(session, tables.Version, 'firered')
emerald_version_group = emerald.version_group
xd_version_group = util.get(session, tables.Version, 'xd').version_group
colo_version_group = util.get(session, tables.Version, 'colosseum').version_group
tutor = util.get(session, tables.PokemonMoveMethod, 'tutor')
level_up = util.get(session, tables.PokemonMoveMethod, 'level-up')
# According to every source I could find, the following can be taught to
# exactly the same set of Pokémon which learn it from the FR/LG/E tutor: --ete
for move_identifier in '''
body-slam
double-edge
dream-eater
icy-wind
mimic
seismic-toss
substitute
swagger
thunder-wave
'''.split():
move = util.get(session, tables.Move, move_identifier)
print move
query = session.query(tables.PokemonMove.pokemon_id)
query = query.filter_by(method=tutor)
query = query.filter_by(move=move)
em = set(p for (p, ) in query.filter_by(version_group=emerald.version_group).all())
fr = set(p for (p, ) in query.filter_by(version_group=fire_red.version_group).all())
assert not fr or not em.symmetric_difference(fr)
for pokemon_id in em:
pokemon_move = tables.PokemonMove()
pokemon_move.pokemon_id = pokemon_id
pokemon_move.move = move
pokemon_move.method = tutor
pokemon_move.level = 0
pokemon_move.version_group = xd_version_group
session.add(pokemon_move)
# These are only found in XD:
xd_tutor_data = {
'nightmare': 'butterfree clefairy clefable jigglypuff wigglytuff meowth '
'persian abra kadabra alakazam slowpoke slowbro gastly haunter gengar '
'drowzee hypno exeggcute exeggutor lickitung starmie mr-mime jynx '
'lapras porygon mewtwo mew hoothoot noctowl cleffa igglybuff natu xatu '
'aipom espeon umbreon murkrow slowking misdreavus girafarig dunsparce '
'sneasel houndour houndoom porygon2 stantler smoochum tyranitar lugia '
'ho-oh celebi ralts kirlia gardevoir masquerain shedinja sableye '
'roselia gulpin swalot spinda shuppet banette duskull dusclops '
'chimecho absol jirachi deoxys '.split(),
'selfdestruct': 'geodude graveler golem grimer muk shellder cloyster '
'gastly haunter gengar onix voltorb electrode exeggcute exeggutor '
'koffing weezing snorlax mewtwo mew sudowoodo pineco forretress '
'steelix qwilfish slugma magcargo corsola seedot nuzleaf shiftry '
'nosepass gulpin swalot wailmer wailord camerupt torkoal lunatone '
'solrock baltoy claydol glalie metang metagross regirock regice '
'registeel'.split(),
'sky-attack': 'pidgey pidgeotto pidgeot spearow fearow doduo dodrio '
'aerodactyl articuno zapdos moltres mew hoothoot noctowl togetic '
'natu xatu murkrow delibird skarmory ho-oh taillow swellow wingull '
'pelipper swablu altaria'.split(),
'faint-attack': ['mew'],
'fake-out': ['mew'],
'hypnosis': ['mew'],
'night-shade': ['mew'],
'role-play': ['mew'],
'zap-cannon': ['mew'],
}
for move_identifier, pokemon_identifiers in xd_tutor_data.items():
move = util.get(session, tables.Move, move_identifier)
for pokemon_identifier in pokemon_identifiers:
species = util.get(session, tables.PokemonSpecies, pokemon_identifier)
try:
pokemon, = species.pokemon
except ValueError:
assert pokemon_identifier == 'deoxys'
pokemon = species.default_pokemon
print move, pokemon
pokemon_move = tables.PokemonMove()
pokemon_move.pokemon = pokemon
pokemon_move.move = move
pokemon_move.method = tutor
pokemon_move.level = 0
pokemon_move.version_group = xd_version_group
session.add(pokemon_move)
# And unfortunately, we have to copy level-up moves. To both XD and Colosseum.
for pokemon_id, move_id, level in set(
session.query(
tables.PokemonMove.pokemon_id,
tables.PokemonMove.move_id,
tables.PokemonMove.level,
)
.filter_by(method=level_up)
.filter_by(version_group=emerald_version_group)
):
for version_group in xd_version_group, colo_version_group:
print pokemon_id, move_id
pokemon_move = tables.PokemonMove()
pokemon_move.pokemon_id = pokemon_id
pokemon_move.move_id = move_id
pokemon_move.method = level_up
pokemon_move.level = level
pokemon_move.version_group = version_group
session.add(pokemon_move)
session.commit()