def json_to_database(eng): with eng.connect() as conn: try: with open('pokedex.json') as f: sql = f.read() json_data = json.loads(sql) r = Review(int(json_data['id']), json_data['name_english'], json_data['name_japanese'], json_data['name_chinese'], json_data['name_french'], json_data['type'], int(json_data['base_HP']), int(json_data['base_Attack']), int(json_data['base_Defense']), int(json_data['base_Sp_Attack']), int(json_data['base_Sp_Defense']), int(json_data['base_Speed'])) Session.add(r) Session.commit() except ValueError as err: return False
CHARACTER SET utf8\ COLLATE utf8_unicode_ci;') f = open('pokedex.json') sql = f.read() json_data = json.loads(sql) for element in json_data: type_of_product = "" for i in element['type']: type_of_product += i product = Product(type_of_product) eng_name = Names("english", element['name']['english'], product) jpa_name = Names("japanese", element['name']['japanese'], product) chie_name = Names("chinese", element['name']['chinese'], product) fr_name = Names("french", element['name']['french'], product) detail = Details(element['base']['HP'], element['base']['Attack'], element['base']['Defense'], element['base']['Sp. Attack'], element['base']['Sp. Defense'], element['base']['Speed'], product) session.add(product) session.add(eng_name) session.add(jpa_name) session.add(chie_name) session.add(fr_name) session.add(detail) session.commit() session.close()