def save_settings(values): settings = { 'chrome_path': values['gui.chrome_path'], 'python_command': values['gui.python_command'], 'track_clicks': values['gui.track_clicks'], 'debug_output': values['gui.debug_output'], } JsonData.dump_json(settings, 'gui_settings.json', pretty=True)
def _process_get_data(self, data): try: get_data_ship = data['api_data']['api_mst_ship'] shp.ships.update_ship_library(get_data_ship) JsonData.dump_json(get_data_ship, 'data|temp|get_data_ship.json') except KeyError: Log.log_debug("No getData found in API response.") return None
def get_and_save_wgtf_data(cls): """Wrapper method for retrieving and storing WCTF data. """ Log.log_debug("Attempting to get WCTF data.") suffixes = cls._get_suffix_data() name_db = cls._get_ship_name_data(suffixes) Log.log_debug("Successfully downloaded WCTF data.") JsonData.dump_json(name_db, 'data|temp|wctf.json')
def load_wctf_names(self, force_update=False): if force_update: WhoCallsTheFleetData.get_and_save_wgtf_data() try: temp_db = JsonData.load_json('data|temp|wctf.json') except FileNotFoundError: WhoCallsTheFleetData.get_and_save_wgtf_data() temp_db = JsonData.load_json('data|temp|wctf.json') self.name_db = {} for key in temp_db: self.name_db[int(key)] = temp_db[key]
def _get_ship_name_data(suffixes): """Method for retrieving and parsing the WCTF ship name data with appropriate suffixes. Args: suffixes (dict): suffix dict Returns: dict: dict of ship names """ db_res = requests.get(WCTF_DB_URL) name_db = {} if db_res.status_code == 200: db_split = db_res.text.split('\n') for line in db_split: line = line.strip() if not line: continue line_dict = JsonData.load_json_str(line) suffix_id = line_dict['name']['suffix'] jp_name = line_dict['name']['ja_jp'] non_jp_name = line_dict['name']['ja_romaji'].title() if suffix_id: jp_name += f" {suffixes[suffix_id]['jp']}" if non_jp_name: non_jp_name += f" {suffixes[suffix_id]['non_jp']}" name_db[line_dict['id']] = { 'jp': jp_name, 'non_jp': non_jp_name } else: Log.log_warn("Could not download WCTF ship data.") return name_db
def _get_suffix_data(): """Method for retrieving and parsing the WCTF suffix data needed to generate complete ship names. Returns: dict: suffix dict """ suf_res = requests.get(WCTF_SUFFIX_URL) suffixes = {} if suf_res.status_code == 200: suf_split = suf_res.text.split('\n') for line in suf_split: line = line.strip() if not line: continue line_dict = JsonData.load_json_str(line) suffixes[line_dict['id']] = { 'jp': line_dict['ja_jp'], 'non_jp': line_dict['ja_romaji'] } else: Log.log_warn("Could not download WCTF suffix data.") return suffixes
def _load_quest_data(self): Log.log_debug("Loading Quest data.") quest_data = JsonData.load_json('data|quests|quests.json') for quest_name in quest_data: quest = Quest(quest_name, quest_data[quest_name]) self.quest_library[quest_name] = quest self.quest_library[quest.quest_id] = quest self.quest_id_to_name[quest_data[quest_name]['id']] = quest_name
def update_ship_library_from_json(self): try: ship_data = JsonData.load_json('data|temp|get_data_ship.json') shp.ships.update_ship_library(ship_data) except FileNotFoundError as e: Log.log_error( "get_data_ship.json not found. Please run kcauto from the " "Kancolle splash screen to download data.") Log.log_error(e) sys.exit(1)
def __init__(self): Log.log_success("Initializing kcauto.") if arg.args.parsed_args.cfg_path: self.cfg_path = arg.args.parsed_args.cfg_path else: cfg_file = arg.args.parsed_args.cfg self.cfg_path = JsonData.create_path(f'configs|{cfg_file}.json') self.initialize_config() if not self.general: Log.log_error("Error loading config.") exit(1)
def _calc_quest_layout(cls): quest_data = JsonData.load_json('data|quests|quests.json') quest_layout = {} for quest_name in quest_data: quest = quest_data[quest_name] quest['name'] = quest_name if quest['name'][0] not in quest_layout: quest_layout[quest['name'][0]] = {} if quest['type'] not in quest_layout[quest['name'][0]]: quest_layout[quest['name'][0]][quest['type']] = [quest['name']] else: quest_layout[quest['name'][0]][quest['type']].append( quest['name']) return quest_layout
def _load_map_data(self, sortie_map): if self.map_data is None or self.map_data.name != sortie_map.value: data = JsonData.load_json(f'data|combat|{sortie_map.value}.json') self.map_data = MapData(sortie_map, data)
def load_settings(): try: settings = JsonData.load_json('gui_settings.json') return settings except FileNotFoundError: return {}
def load_cfg(path, window, event, values): cfg = JsonData.load_json(path) ConfigMethods.unpack_config_dict(window, cfg)
def save_cfg(path, window, values): cfg = ConfigMethods.generate_config_dict(window, values) JsonData.dump_json(cfg, path, pretty=True)
def _load_cfg_json(self): return JsonData.load_json(self.cfg_path)