Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quid solved #428

Merged
merged 9 commits into from
Oct 19, 2024
29 changes: 18 additions & 11 deletions src/scribe_data/cli/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

from scribe_data.utils import DEFAULT_JSON_EXPORT_DIR

# MARK: CLI Variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove marks from the code in the future @Collins-Webdev as these are meant to make the files more manageable to navigate.


LANGUAGE_DATA_EXTRACTION_DIR = Path(__file__).parent.parent / "language_data_extraction"

LANGUAGE_METADATA_FILE = (
Expand Down Expand Up @@ -62,17 +60,26 @@
for lang, lang_data in language_metadata.items():
lang_lower = lang.lower()

# Handle sub-languages if they exist.
if "sub_languages" in lang_data:
for sub_lang, sub_lang_data in lang_data["sub_languages"].items():
sub_lang_lower = sub_lang.lower()
language_map[sub_lang_lower] = sub_lang_data
language_to_qid[sub_lang_lower] = sub_lang_data["qid"]
sub_qid = sub_lang_data.get("qid")

if sub_qid is None:
print(f"Warning: 'qid' missing for sub-language {sub_lang} of {lang}")

else:
language_map[sub_lang_lower] = sub_lang_data
language_to_qid[sub_lang_lower] = sub_qid

else:
# Handle the main language directly.
language_map[lang_lower] = lang_data
language_to_qid[lang_lower] = lang_data["qid"]
qid = lang_data.get("qid")
if qid is None:
print(f"Warning: 'qid' missing for language {lang}")

else:
language_map[lang_lower] = lang_data
language_to_qid[lang_lower] = qid


# MARK: Correct Inputs
Expand Down Expand Up @@ -139,7 +146,7 @@ def print_formatted_data(data: Union[dict, list], data_type: str) -> None:
for item in value:
if isinstance(item, dict):
for sub_key, sub_value in item.items():
print(f" {sub_key:<{max_key_length}} : {sub_value}")
print(f" {sub_key:<{max_sub_key_length}} : {sub_value}")

else:
print(f" {item}")
Expand Down Expand Up @@ -210,12 +217,12 @@ def validate_single_item(item, valid_options, item_type):
):
closest_match = difflib.get_close_matches(item, valid_options, n=1)
closest_match_str = (
f" The closest matching {item_type} is '{closest_match[0]}'."
f" The closest matching {item_type} is {closest_match[0]}."
if closest_match
else ""
)

return f"Invalid {item_type} '{item}'.{closest_match_str}"
return f"Invalid {item_type} {item}.{closest_match_str}"

return None

Expand Down
Loading