def run(self): csv_path = os.path.join(self.config.csv.base, self.config.csv.path.predefined_decks) rows = read_csv(csv_path) rows = self.value_dict_to_list(rows) rows = self.convert_row_tid(tid_key="tid", key="name_en", rows=rows) # convert sc_key in spells to keys for row in rows: spells = row.get('spells') if spells: cards = [] for s in spells: card = self.get_card(sc_key=s) if card is not None: cards.append(card.get('key')) row['spells'] = cards if self.i18n: tid = row.get('tid') if tid: row.update({'_lang': { 'name': self.text_all_lang(tid), }}) json_path = os.path.join(self.config.json.base, self.config.json.predefined_decks) self.save_json(rows, json_path)
def run(self): csv_path = os.path.join(self.config.csv.base, self.config.csv.path.spell_sets) rows = read_csv(csv_path) rows = self.value_dict_to_list(rows) # convert spells to keys for row in rows: spells = row.get('spells') card_keys = [] for spell in spells: card = self.get_card(sc_key=spell) if not card: card_keys.append(spell) else: card_keys.append(card.get('key')) # ensure uniques: battle healer is listed twice in-game unique_card_keys = [] for c in card_keys: if c not in unique_card_keys: unique_card_keys.append(c) row['spells'] = unique_card_keys json_path = os.path.join(self.config.json.base, self.config.json.spell_sets) self.save_json(rows, json_path)
def run(self): data = read_csv(self.csv_path) # data = self.load_csv(exclude_empty=True) for id, row in enumerate(data): row['id'] = 16000000 + id self.save_json(data)
def run(self): csv_path = os.path.join(self.config.csv.base, self.config.csv.path.draft_deck) rows = read_csv(csv_path) rows = self.value_dict_to_list(rows) json_path = os.path.join(self.config.json.base, self.config.json.draft_deck) self.save_json(rows, json_path)
def run(self): csv_path = os.path.join(self.config.csv.base, self.config.csv.path.consumables) rows = read_csv(csv_path) rows = self.value_dict_to_list(rows) rows = self.parse_tids(rows) json_path = os.path.join(self.config.json.base, self.config.json.consumables) self.save_json(rows, json_path)
def run(self): data_list = read_csv(self.csv_path) out = [] for index, row in enumerate(data_list): if row.get('name') is not None: hi = row.get('index_hi', '') lo = row.get('index_lo', '') sc = row.get('sc_file', '')[3:] # truncate path sc/ row.update(key=f"emote_{hi}_{lo}", file_key=f"{sc}:{hi}:{lo}") out.append(row) self.save_json(out)
def run(self): data = read_csv(self.csv_path) for i, row in enumerate(data): row_name = row.get('name') if row_name is None: continue row.update(dict( key=row_name, id=65000000 + i, )) if row.get('tid'): row.update(dict(name_en=self.text(row["tid"], "EN"))) data = self.value_dict_to_list(data) self.save_json(data)
def run(self): data_list = read_csv(self.csv_path) out = [] id_ = 0 for index, row in enumerate(data_list): if row.get('name') is not None: row.update({ 'id': int(self.config.scid.game_modes.format(id_)), 'name_en': row.get('name_en') or row.get('name'), }) id_ += 1 row = self.row_parse_tid(row) row = self.row_parse_dict_list(row) row = self.row_force_list(row, "predefined_decks") out.append(row) out = [o for o in out if o['id']] self.save_json(out)
def convert_text(self, csv_path, first_key=None): data_list = read_csv(csv_path) out = [] for index, row in enumerate(data_list): row["sc_key"] = row.pop(first_key) # replace quotes for k, v in row.items(): if "\\q" in v: s = v toggle = 0 while "\\q" in s: if toggle == 0: s = s.replace('\\q', '“', 1) else: s = s.replace('\\q', '”', 1) toggle += 1 row[k] = s out.append(row) return out
def main(): print(CSV_FOLDER) for root, dirs, files in os.walk(CSV_FOLDER): for name in files: if not name.endswith('.csv'): continue full_path = os.path.join(root, name) dir_name = os.path.dirname(full_path) folder_name = os.path.split(dir_name)[-1] # make folder dist_folder = os.path.join(DIST_FOLDER, folder_name) os.makedirs(dist_folder, exist_ok=True) data = csv2json.read_csv(full_path) dist_file = os.path.join(dist_folder, f"{name.split('.')[0]}.json") with open(dist_file, 'w') as f: json.dump(data, f, indent=4) print(dist_file)
def run(self): """Generate json.""" arenas = read_csv(self.csv_path) # add scid base_scid = 54000000 for index, row in enumerate(arenas): arena_id = min(12, row["arena"]) league_id = max(0, row['arena'] - 12) row.update({ "id": base_scid + index, "key": self.arena_key(row), "title": self.text(row["tid"], "EN"), "subtitle": self.text(row["subtitle_tid"], "EN"), "arena_id": arena_id, "league_id": league_id, }) row.pop('tid', None) row.pop('subtitle_tid', None) # sort arenas by trophy limit arenas = sorted(arenas, key=lambda x: x['trophy_limit']) self.save_json(arenas)