Skip to content

Commit

Permalink
added reviewed MD file with Python script to convert JSON to MD
Browse files Browse the repository at this point in the history
  • Loading branch information
hmkamel committed May 12, 2024
1 parent 10e2a8c commit a92fe7e
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions import json_as_md.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
import json


# Function to extract endpoints from JSON data and write to markdown file
def extract_and_write_endpoints(json_file_path, markdown_file_path):
# Read JSON data from file
with open(json_file_path, 'r') as json_file:
with open(json_file_path, "r") as json_file:
data = json.load(json_file)

# Open markdown file for writing
with open(markdown_file_path, 'w') as markdown_file:
with open(markdown_file_path, "w") as markdown_file:
# Iterate through JSON data and write endpoints to markdown file
for category, endpoints in data.items():
markdown_file.write(f'## {category}\n\n')
markdown_file.write(f"## {category}\n\n")
for endpoint, details in endpoints.items():
markdown_file.write(f'### {category}.{endpoint}()\n\n')
if 'note' in details:
markdown_file.write(''.join(details['note']) + '\n\n')
markdown_file.write(f"### {category}.{endpoint}()\n\n")
if "note" in details:
markdown_file.write("".join(details["note"]) + "\n\n")
else:
markdown_file.write('No Description' + '\n\n')
markdown_file.write("No Description" + "\n\n")

# Check if parameters exist
if 'parameters' in details:
markdown_file.write('| Parameter | Type | Description | Required |\n')
markdown_file.write('|:---------|:----:|:------------|:--------:|\n')
for param_name, param_details in details['parameters'].items():
param_type = param_details.get('type', 'Unknown') # Check if 'type' key exists
param_note = param_details.get('note', 'No description available') # Check if 'note' key exists
required = param_details.get('required', False) # Check if 'required' key exists
markdown_file.write(f'| `{param_name}` | `{param_type}` | {param_note} | {"True" if required else "False"} |\n')

if "parameters" in details:
markdown_file.write(
"| Parameter | Type | Description | Required |\n"
)
markdown_file.write(
"|:---------|:----:|:------------|:--------:|\n"
)
for param_name, param_details in details[
"parameters"
].items():
param_type = param_details.get(
"type", "Unknown"
) # Check if 'type' key exists
param_note = param_details.get(
"note", "No description available"
) # Check if 'note' key exists
required = param_details.get(
"required", False
) # Check if 'required' key exists
markdown_file.write(
f'| `{param_name}` | `{param_type}` | {param_note} | {"True" if required else "False"} |\n'
)

markdown_file.write(f"\nlink: ```{details['link']}```\n\n")

# Add the "---" line after all endpoints in the category are processed
markdown_file.write('---\n\n')
markdown_file.write("---\n\n")


# File paths
json_file_path = '/home/ham/Downloads/api.json'
markdown_file_path = 'methods.md'
json_file_path = "/home/ham/Downloads/api.json"
markdown_file_path = "methods.md"

# Call the function
extract_and_write_endpoints(json_file_path, markdown_file_path)

0 comments on commit a92fe7e

Please sign in to comment.