Last active
September 9, 2022 10:00
-
-
Save jze/f927c66b01757db0c1d13e7f4d71c9c3 to your computer and use it in GitHub Desktop.
Generate Markdown form a Frictionless Data Tabular Resoure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from frictionless import Resource | |
import sys | |
resource = Resource(sys.argv[1]) | |
table = False | |
print("## Attributes") | |
print() | |
if table: | |
print("| Field | Description |") | |
print("| ------ | ------------ |") | |
for f in resource.schema.fields: | |
description = f.description | |
if f.constraints and 'enum' in f.constraints: | |
description += " (allowed values: `" + "`, `".join(f.constraints['enum']) + "`)" | |
if f.type == 'date': | |
if f.format != 'default': | |
description += ", format " + f.format | |
else: | |
description += ", in ISO 8601 format" | |
if table: | |
print("| `"+ f.name + "` | " +description+ " |") | |
else: | |
print("- `"+ f.name + "` – " +description) | |
print() | |
if 'primaryKey' in resource.schema: | |
if isinstance(resource.schema['primaryKey'], list): | |
print("The fields `"+ "`, `".join(resource.schema['primaryKey'][:-1]) + "` and `"+ resource.schema['primaryKey'][-1] +"` form a unique identifier.") | |
else: | |
print("The field `" + resource.schema['primaryKey'] + "` is the unique identificator.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment