diff --git a/mtgsqlive/__init__.py b/mtgsqlive/__init__.py index c6b93c4..e62bd6a 100644 --- a/mtgsqlive/__init__.py +++ b/mtgsqlive/__init__.py @@ -22,7 +22,7 @@ def init_logger() -> None: logging.FileHandler( str( LOG_DIR.joinpath( - "mtgsqlive_" + str(time.strftime("%Y-%m-%d_%H:%M:%S")) + ".log" + "mtgsqlive_" + str(time.strftime("%Y-%m-%d_%H-%M-%S")) + ".log" ) ) ), diff --git a/mtgsqlive/json2sql.py b/mtgsqlive/json2sql.py index fc8fcd4..a959bba 100644 --- a/mtgsqlive/json2sql.py +++ b/mtgsqlive/json2sql.py @@ -227,7 +227,7 @@ def parse_and_import_cards( :param sql_connection: Database connection """ LOGGER.info("Loading JSON into memory") - json_data = json.load(input_file.open("r")) + json_data = json.load(input_file.open("r", encoding="utf8")) LOGGER.info("Building sets") for set_code, set_data in json_data.items(): @@ -246,6 +246,11 @@ def parse_and_import_cards( token_attr = handle_token_row_insertion(token, set_code) sql_dict_insert(token_attr, "tokens", sql_connection) + for language, translation in set_data["translations"].items(): + LOGGER.debug("Inserting set_translation row for {}".format(language)) + set_translation_attr = handle_set_translation_row_insertion(language, translation, set_code) + sql_dict_insert(set_translation_attr, "set_translations", sql_connection) + sql_connection.commit() @@ -362,6 +367,28 @@ def handle_ruling_rows( return rulings +def handle_set_translation_row_insertion( + language: str, + translation: str, + set_name: str +) -> Dict[str, Any]: + """ + This method will take the set translation data and convert it, preparing + for SQLite insertion + :param language: The language of the set translation + :param translation: The set name translated in to the given language + :param set_name: Set name, as it's a card element + :return: Dictionary ready for insertion + """ + set_translation_insert_values: Dict[str, Any] = { + "language": language, + "translation": translation, + "setCode": set_name + } + + return set_translation_insert_values + + def handle_token_row_insertion( token_data: Dict[str, Any], set_name: str ) -> Dict[str, Any]: