Datasets:
File size: 964 Bytes
bd9bf59 56b2ea6 bd9bf59 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import os
import re
folder_path = "data"
langs = ["eu", "es"]
output = "configs:\n"
for lang in langs:
for root, dirs, files in os.walk(f"{folder_path}/{lang}"):
for file in sorted(files):
file_path = os.path.join(root, file)
rel_path = os.path.relpath(file_path, folder_path)
output += (
f"- config_name: {lang}_{os.path.splitext(file)[0]}\n data_files:\n"
)
output += f' - split: test\n path: "{folder_path}/{rel_path}"\n'
# read existing contents of README.md
with open("README.md", "r") as f:
readme_content = f.read()
# find end of YAML header using regular expressions
yaml_end = re.search(r"---\n\n", readme_content).start()
# insert generated YAML output after YAML header
readme_content = readme_content[:yaml_end] + output + readme_content[yaml_end:]
# write updated contents to README.md
with open("README.md", "w") as f:
f.write(readme_content)
|