def create_modern_only_output() -> Dict[str, Any]: """ Use gamepedia to determine all sets that are legal in the modern format. Return an AllSets version that only has Modern legal sets. :return: AllSets for Modern only """ modern_data: Dict[str, Any] = {} for set_code in gamepedia.get_modern_sets(): set_file = mtgjson4.COMPILED_OUTPUT_DIR.joinpath( util.win_os_fix(set_code) + ".json" ) if not set_file.is_file(): LOGGER.warning( "Set {} not found in compiled outputs (Modern)".format(set_code) ) continue with set_file.open("r", encoding="utf-8") as f: file_content = json.load(f) modern_data[set_code] = file_content return modern_data
def write_to_file(set_name: str, file_contents: Any, set_file: bool = False) -> None: """ Write the compiled data to a file with the set's code Will ensure the output directory exists first """ mtgjson4.COMPILED_OUTPUT_DIR.mkdir(exist_ok=True) with mtgjson4.COMPILED_OUTPUT_DIR.joinpath( util.win_os_fix(set_name) + ".json").open("w", encoding="utf-8") as f: # Only do this for set files, not everything if set_file: file_contents["tokens"] = mtgjson_to_dict( file_contents.get("tokens", [])) file_contents["cards"] = mtgjson_to_dict( file_contents.get("cards", [])) json.dump( file_contents, f, sort_keys=True, ensure_ascii=False, indent=mtgjson4.PRETTY_OUTPUT.get(), )
def create_standard_only_output() -> Dict[str, Any]: """ Use whatsinstandard to determine all sets that are legal in the standard format. Return an AllSets version that only has Standard legal sets. :return: AllSets for Standard only """ standard_data: Dict[str, Any] = {} # Get all sets currently in standard standard_url_content = util.get_generic_session().get(STANDARD_API_URL) standard_json = [ set_obj["code"].upper() for set_obj in json.loads(standard_url_content.text)["sets"] if str(set_obj["enter_date"]) < datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") < str(set_obj["exit_date"]) ] for set_code in standard_json: set_file = mtgjson4.COMPILED_OUTPUT_DIR.joinpath( util.win_os_fix(set_code) + ".json" ) if not set_file.is_file(): LOGGER.warning( "Set {} not found in compiled outputs (Standard)".format(set_code) ) continue with set_file.open("r", encoding="utf-8") as f: file_content = json.load(f) standard_data[set_code] = file_content return standard_data
def write_to_file(set_name: str, file_contents: Any, set_file: bool = False) -> None: """ Write the compiled data to a file with the set's code Will ensure the output directory exists first """ mtgjson4.COMPILED_OUTPUT_DIR.mkdir(exist_ok=True) with mtgjson4.COMPILED_OUTPUT_DIR.joinpath( util.win_os_fix(set_name) + ".json" ).open("w", encoding="utf-8") as f: # Only do this for set files, not everything if set_file: file_contents["tokens"] = mtgjson_to_dict(file_contents.get("tokens", [])) file_contents["cards"] = mtgjson_to_dict(file_contents.get("cards", [])) json.dump(file_contents, f, indent=4, sort_keys=True, ensure_ascii=False)
def write_to_file(set_name: str, file_contents: Any, do_cleanup: bool = False) -> None: """ Write the compiled data to a file with the set's code Will ensure the output directory exists first """ mtgjson4.COMPILED_OUTPUT_DIR.mkdir(exist_ok=True) with mtgjson4.COMPILED_OUTPUT_DIR.joinpath( util.win_os_fix(set_name) + ".json").open("w", encoding="utf-8") as f: if do_cleanup and isinstance(file_contents, dict): if "cards" in file_contents: file_contents["cards"] = remove_unnecessary_fields( file_contents["cards"]) if "tokens" in file_contents: file_contents["tokens"] = remove_unnecessary_fields( file_contents["tokens"]) json.dump(file_contents, f, indent=4, sort_keys=True, ensure_ascii=False)
def __handle_compiling_sets(set_codes: List[str], build_type: str) -> Dict[str, Any]: """ Given a list of sets, compile them into an output file (Modern.json, Standard.json, etc) :param set_codes: List of sets to include :param build_type: String to show on display :return: Compiled output """ return_data = {} for set_code in set_codes: set_file = mtgjson4.COMPILED_OUTPUT_DIR.joinpath( util.win_os_fix(set_code) + ".json") if not set_file.is_file(): LOGGER.warning( f"Set {set_code} not found in compiled outputs ({build_type})") continue with set_file.open(encoding="utf-8") as f: file_content = json.load(f) return_data[set_code] = file_content return return_data