Data Quality Spec 2 MarkDown v1

parent 8fdcc094
......@@ -4,38 +4,57 @@
# 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
# and branch in French version by Jailbreak Paris
#
import docopt
'''Data Quality Specification to Markdown
Usage:
data_quality_spec_to_md.py JSON_SPEC_FILE TARGET_DIR
Options:
-h --help Show this screen.
--version Show version.
'''
import json
import os
import requests
from docopt import docopt
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"
# 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 download_spec_source_file(url, target_dir="./"):
# filename = os.path.basename(url)
# r = requests.get(url)
# if r.status_code < 300:
# json_str = json.dumps(r.json())
# with open(filename, 'w') as f:
# f.write(json_str)
# return filename
def generate_documentation():
def generate_documentation(JSON_SPEC_FILE="spec-fr_FR.json", TARGET_DIR="./"):
'''loads specification schema errors given by frictionlessdata.io
for each error transform it to a correspond md files
'''
root_dir = "errors"
try:
assert os.path.exists(TARGET_DIR)
assert os.path.exists(JSON_SPEC_FILE)
root_dir = os.path.join(TARGET_DIR, "errors")
if not os.path.exists(root_dir):
os.makedirs(root_dir)
except FileExistsError:
pass
with open(os.path.join("spec-fr_FR.json"), "r", encoding="utf-8") as _file:
with open(JSON_SPEC_FILE, "r", encoding="utf-8") as _file:
specs = json.load(_file)
readme = "./README.md"
readme = os.path.join(root_dir, "index.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_title = "## {}\n".format(error["name"])
md_info = "\n".join(
["**Type d'erreur** | **Contexte** | **Poids**", ":---: | :---: | :---:",
("{} | {} | {} |").format(error["type"], error["context"], error["weight"])
......@@ -43,18 +62,21 @@ def generate_documentation():
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])
print("Generating markdown file", md_filename)
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)
content = "\n\n".join(["# Types d'erreur"] + index_content)
readme_file.write(content)
print("Generating index file for errors:", readme)
def main():
def main(kwargs):
""" Converts Data Quality Specification Schema into markdown """
generate_documentation()
generate_documentation(**kwargs)
if __name__ == '__main__':
main()
main(docopt(__doc__, version='1.0'))
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