def import_data(): #import data from csv files #import attack datas con = low_level.open_db('pokedb.db') poke_csv = "poke_import.csv" attacks_csv = "attacks_import.csv" locations_csv = "location_import.csv" local_reference_csv = "location_reference.csv" evolutions_csv = "evolution_import.csv" pokereader = csv.reader(open(poke_csv)) attackreader = csv.reader(open(attacks_csv)) locationreader = csv.reader(open(locations_csv)) locationrefreader = csv.reader(open(local_reference_csv)) evolutionsreader = csv.reader(open(evolutions_csv)) print("\n\n IMPORTING DATA") insert_locations(locationreader, con, 'name,description') insert_attacks( attackreader, con, 'name,damage,effect,targets,power_points,accuracy,location_name') insert_pokemon( pokereader, con, 'name,type1,type2,hp,primary_attack,secondary_attack,evolution_level') insert_location_references(locationrefreader, con, 'pokemon_name,location_name') insert_evolutions(evolutionsreader, con) con.close()
def execute(string): #assumes properly formatted input #print("\nExecuting: " + string) con = low_level.open_db(DATABASE_NAME) results = low_level.execute_sql(string, con) con.close() #print("Done.") return results
def check_in_locations(word): con = low_level.open_db('pokedb.db') result = low_level.execute_sql( 'select * from locations where name = "' + word.lower() + '";', con) con.close() if result: return True return False
def check_in_attacks(word): con = low_level.open_db("pokedb.db") attack = word.lower().strip() result = low_level.execute_sql( 'select name from attacks where name = "' + attack + '";', con) con.close() if result: return True return False
def check_in_pokemon(word): con = low_level.open_db('pokedb.db') pokemon = word.lower() result = low_level.execute_sql( 'select * from pokemon where name = "' + pokemon + '";', con) con.close() if result: return True return False
def create_tables(): print("\n\nCREATING POKE DB...\n") exec_string = [] exec_string.append( "create table locations (name text primary key,\n " + "description text, \n" + "north_exit text, \n" + "east_exit text, \n" + "south_exit text, \n" + "west_exit text, \n" + "foreign key(north_exit) references locations(name),\n" + "foreign key(east_exit) references locations(name),\n" + "foreign key(south_exit) references locations(name),\n" + "foreign key(west_exit) references locations(name)" + ");") exec_string.append( "create table attacks (name text primary key, \n" + "damage integer, \n" + "effect text, \n" + "targets text, \n" + "power_points integer, \n" + "accuracy integer, \n" + "location_name text not null, \n" + "foreign key (location_name) references locations(name)" + ");") exec_string.append( "create table pokemon (" + "name text primary key,\n" + "hp integer not null, \n" + " type1 text not null, \n" + "type2 text,\n" + "primary_attack text,\n" + "evolution_level integer,\n" + "secondary_attack text,\n" + "foreign key(primary_attack) references attacks(name),\n" + "foreign key(secondary_attack) references attacks(name));") exec_string.append( "create table location_reference(" + 'pokemon_name text not null, location_name text not null,primary key (pokemon_name,location_name), foreign key (pokemon_name) references pokemon(name), foreign key (location_name) references locations(name));' ) exec_string.append( "create table evolutions (" + " parent_poke text not null, child_poke text not null, evolved integer default 0, item_used integer default 0, item text default '', " + "traded integer default 0, bred integer default 0, notes text, primary key (parent_poke, child_poke)," + "foreign key (parent_poke) references pokemon(name), foreign key (child_poke) references pokemon(name));" ) con = low_level.open_db('pokedb.db') print(con) print("CREATING TABLES \n") for i in exec_string: print("\nexecuting: " + i) out = low_level.execute_sql(i, con) print("output: \n") if out != None: for o in out: print(o) print("next statement") out = low_level.execute_sql( "select * from sqlite_master where type = 'table' order by name;", con) print("\n\nRESULTANT TABLES:") for o in out: print(o) con.commit() print("FINISHED CREATING TABLES.") con.close()