mirror of
https://github.com/correl/mtgsqlive.git
synced 2024-11-21 19:18:41 +00:00
Implement set_translation
import (#17)
* Replace colons with hyphens in log filenames to be compatible with Windows. * Always open the json file as UTF8 encoding as the default on Windows is different. * Add set_translation data import.
This commit is contained in:
parent
1de6e57e41
commit
0bd4089efc
2 changed files with 29 additions and 2 deletions
|
@ -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"
|
||||
)
|
||||
)
|
||||
),
|
||||
|
|
|
@ -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]:
|
||||
|
|
Loading…
Reference in a new issue