Skip to content

Commit

Permalink
Enhance get_data Functionality for Language and All Data-Type Retriev…
Browse files Browse the repository at this point in the history
…al in Scribe-Data CLI
  • Loading branch information
KesharwaniArpita authored Oct 27, 2024
1 parent 40c41ab commit aa57eed
Showing 1 changed file with 20 additions and 18 deletions.
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

0 comments on commit aa57eed

Please sign in to comment.