X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/220857af92f919afc7dce4ccd3f7d9b277c70204..cf773b3baa415852a5605542ab5a75c0f5950223:/pokedex/db/load.py diff --git a/pokedex/db/load.py b/pokedex/db/load.py index 2b7c6ae..c77064f 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -96,7 +96,7 @@ def _get_verbose_prints(verbose): return print_start, print_status, print_done -def load(session, tables=[], directory=None, drop_tables=False, verbose=False, safe=True, recursive=False): +def load(session, tables=[], directory=None, drop_tables=False, verbose=False, safe=True, recursive=True, langs=None): """Load data from CSV files into the given database session. Tables are created automatically. @@ -123,6 +123,9 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s `recursive` If set to True, load all dependent tables too. + + `langs` + List of identifiers of extra language to load, or None to load them all """ # First take care of verbosity @@ -300,6 +303,23 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s print_done() + + print_start('Translations') + transl = translations.Translations(csv_directory=directory) + + new_row_count = 0 + for translation_class, rows in transl.get_load_data(langs): + table_obj = translation_class.__table__ + if table_obj in table_objs: + insert_stmt = table_obj.insert() + session.connection().execute(insert_stmt, rows) + session.commit() + # We don't have a total, but at least show some increasing number + new_row_count += len(rows) + print_status(str(new_row_count)) + + print_done() + # SQLite check if session.connection().dialect.name == 'sqlite': session.connection().execute("PRAGMA integrity_check")