Generating md files for each error of spec-fr_FR.json

parents
#!/usr/bin/env python3
#
# data_quality_spec_to_md:
# Generate Data Quality Specification from JSON Schema to Markdown
# Data Quality Specification are defined frictionlessdata.io:
# https://github.com/frictionlessdata/data-quality-spec
# and branch in French version by Jailbreak Pars
#
import docopt
import json
import os
FR_SPEC = "https://github.com/Jailbreak-Paris/data-quality-spec/blob/french/spec-fr_FR.json"
RAW_FR_SPEC = "https://raw.githubusercontent.com/Jailbreak-Paris/data-quality-spec/french/spec-fr_FR.json"
def dowload_specs():
pass
def generate_documentation():
'''loads specification schema errors given by frictionlessdata.io
for each error transform it to a correspond md files
'''
root_dir = "errors"
try:
os.makedirs(root_dir)
except FileExistsError:
pass
with open(os.path.join("spec-fr_FR.json"), "r", encoding="utf-8") as _file:
specs = json.load(_file)
readme = "./README.md"
index_content = []
for error_id, error in specs["errors"].items():
md_filename = os.path.join(root_dir, ("{}.md").format(error_id))
md_title = "## Erreur : {}\n".format(error["name"])
md_info = "\n".join(
["**Type d'erreur** | **Contexte** | **Poids**", ":---: | :---: | :---:",
("{} | {} | {} |").format(error["type"], error["context"], error["weight"])
])
md_msg = "### Explication: \n\n{}".format(error["message"])
md_desc = "### Description: \n\n{}".format(error["description"])
md_content = '\n\n'.join([md_title, md_info, md_msg, md_desc])
with open(md_filename, "w") as _mdfile:
_mdfile.write(md_content)
index_content.append("* [{}](./errors/{}.md)".format(error["name"], error_id))
with open(readme, "w") as readme_file:
content = "\n\n".join(["# Erreurs"] + index_content)
readme_file.write(content)
def main():
""" Converts Data Quality Specification Schema into markdown """
generate_documentation()
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment