Skip to content

Commit

Permalink
Merge branch 'master' of github.com:catusf/tudien
Browse files Browse the repository at this point in the history
  • Loading branch information
catusphan committed Dec 17, 2024
2 parents 4703ece + feeca88 commit 92496b2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release_all_external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Build all dictionaries
run: |
python ./bin/convert_all.py --input_folder=$INPUT_DIR --output_folder=$OUTPUT_DIR --extension=tab
python ./bin/convert_all.py --input_folder=$INPUT_DIR --output_folder=$OUTPUT_DIR --extension=tab --filter=Hero
- name: Report the results
run: |
Expand Down
87 changes: 46 additions & 41 deletions bin/dict_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ def generate_summary(dict_dir):
}
)

# Save the list of dictionaries as a JSON file
with open(os.path.join(dict_dir, "dict_summary.json"), "w", encoding="utf-8") as json_file:
json.dump(data, json_file, ensure_ascii=False, indent=4)
# Save the list of dictionaries as a JSON file
json_path = os.path.join(dict_dir, "dict_summary.json")
with open(json_path, 'w', encoding='utf-8') as json_file:
json.dump(data, json_file, ensure_ascii=False, indent=4)

print("JSON file 'dict_summary.json' has been generated.")
return data
print(f"Data file writtend to '{json_path}'.")

return data


def generate_markdown_table(data, extensions, columns):
Expand Down Expand Up @@ -209,42 +211,45 @@ def generate_markdown_table(data, extensions, columns):


def main():
"""Main function to parse arguments and run the processes.""" # noqa: D202

# Parse command-line arguments
parser = argparse.ArgumentParser(description="Generate a dictionary summary.")
parser.add_argument("--dict_dir", type=str, nargs="?", default="dict", help="The directory containing the dictionary files (default is 'dict').")
parser.add_argument("--outfile", type=str, nargs="?", default="dict_summary.md", help="The output report file name (default is 'dict_summary.md').")
parser.add_argument("--extensions", type=str, nargs="?", default=None, help="The extensions that need included in the report. None means all.")
parser.add_argument("--columns", type=str, nargs="?", default=None, help="The columns that will be kept (Other than the download links).")
parser.add_argument("--read-only", choices=["yes", "no"], default="yes", required=False, help="Read data or create it.")

args = parser.parse_args()

# Generate the summary data and save it as a JSON file
ext_str = args.extensions
col_str = args.columns
read_only = args.read_only
dict_dir = args.dict_dir
outfile = args.outfile

extensions = list(SUPPORTED_EXTENSIONS.keys()) if not ext_str else [item.strip() for item in ext_str.split(",")]
columns = list(COLUMNS.keys()) if not col_str else [item.strip() for item in col_str.split(",")]

if read_only == "no":
data = generate_summary(dict_dir)
else:
with open(os.path.join(dict_dir, "dict_summary.json"), "r", encoding="utf-8") as json_file:
data = json.load(json_file)

# Generate the markdown table from the JSON data
markdown_table = generate_markdown_table(data, extensions, columns)

# Save the markdown table to a .md file
with open(os.path.join(dict_dir, outfile), "w", encoding="utf-8") as file:
file.write(markdown_table)

print(f"Summary markdown file '{outfile}' has been generated.")
"""Main function to parse arguments and run the processes.""" # noqa: D202, D401

# Parse command-line arguments
parser = argparse.ArgumentParser(description="Generate a dictionary summary.")
parser.add_argument("--dict_dir", type=str, nargs="?", default="dict", help="The directory containing the dictionary files (default is 'dict').")
parser.add_argument("--outfile", type=str, nargs="?", default="dict_summary.md", help="The output report file name (default is 'dict_summary.md').")
parser.add_argument("--extensions", type=str, nargs="?", default=None, help="The extensions that need included in the report. None means all.")
parser.add_argument("--columns", type=str, nargs="?", default=None, help="The columns that will be kept (Other than the download links).")
parser.add_argument("--read-only", choices=["yes", "no"], default="yes", required=False, help="Read data or create it.")

args = parser.parse_args()

# Generate the summary data and save it as a JSON file
ext_str = args.extensions
col_str = args.columns
read_only = args.read_only
dict_dir = args.dict_dir
outfile = args.outfile

extensions = list(SUPPORTED_EXTENSIONS.keys()) if not ext_str else [item.strip() for item in ext_str.split(",")]
columns = list(COLUMNS.keys()) if not col_str else [item.strip() for item in col_str.split(",")]

if read_only == "no":
data = generate_summary(dict_dir)
else:
json_path = os.path.join(dict_dir, "dict_summary.json")
with open(json_path, 'r', encoding='utf-8') as json_file:
data = json.load(json_file)

# Generate the markdown table from the JSON data
markdown_table = generate_markdown_table(data, extensions, columns)

# Save the markdown table to a .md file
markdown_file = os.path.join(dict_dir, outfile)
with open(markdown_file, 'w', encoding='utf-8') as file:
file.write(markdown_table)
print(f"Data file written to: {markdown_file}")

print(f"Summary markdown file '{outfile}' has been generated.")


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions bin/fix_duplicated_headwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
import os


def main() -> None:
parser = argparse.ArgumentParser(description='Check a tab file for errors',
usage='Usage: python verify_tab_file.py --input data.tab --output data.stats')
Expand Down

0 comments on commit 92496b2

Please sign in to comment.