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

Enhance get Functionality for Language and All Data-Type Retrieval Scribe-Data CLI #491

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/scribe_data/cli/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,44 +79,46 @@ def get_data(
-------
The requested data saved locally given file type and location arguments.
"""
# MARK: Defaults
# Mark: Defaults

output_type = output_type or "json"
if output_dir is None:
if output_type == "csv":
output_dir = DEFAULT_CSV_EXPORT_DIR
elif output_type == "json":
output_dir = DEFAULT_JSON_EXPORT_DIR
elif output_type == "sqlite":
output_dir = DEFAULT_SQLITE_EXPORT_DIR
elif output_type == "tsv":
output_dir = DEFAULT_TSV_EXPORT_DIR
output_dir = {
"csv": DEFAULT_CSV_EXPORT_DIR,
"json": DEFAULT_JSON_EXPORT_DIR,
"sqlite": DEFAULT_SQLITE_EXPORT_DIR,
"tsv": DEFAULT_TSV_EXPORT_DIR,
}.get(output_type, DEFAULT_JSON_EXPORT_DIR)

languages = [language] if language else None
data_types = [data_type] if data_type else None

subprocess_result = False

# MARK: Get All
# Mark: Get All for Specified Language

if all:
if all and language:
print(f"Updating all data types for language: {language}")
query_data(languages=[language], data_type=None, output_dir=output_dir, overwrite=overwrite)
subprocess_result = True

# Mark: Get All for All Languages and Data Types

elif all:
print("Updating all languages and data types ...")
query_data(None, None, None, overwrite)
subprocess_result = True

# MARK: Emojis
# Mark: Emojis

elif data_type in {"emoji-keywords", "emoji_keywords"}:
generate_emoji(language=language, output_dir=output_dir)

# MARK: Query Data
# Mark: Query Data for Specific Language or Data Type

elif language or data_type:
data_type = data_type[0] if isinstance(data_type, list) else data_type

print(
f"Updating data for language(s): {language}; data type(s): {', '.join([data_type])}"
)
print(f"Updating data for language(s): {language}; data type(s): {data_type}")
query_data(
languages=languages,
data_type=data_types,
Expand All @@ -140,6 +142,7 @@ def get_data(
json_input_path = Path(output_dir) / f"{language}/{data_type}.json"

# Proceed with conversion only if the output type is not JSON.

if output_type != "json":
if json_input_path.exists():
convert_wrapper(
Expand All @@ -152,7 +155,6 @@ def get_data(
)

os.remove(json_input_path)

else:
print(
f"Error: Input file '{json_input_path}' does not exist for conversion."
Expand Down
Loading