first
This commit is contained in:
45
edn_to_md.py
Normal file
45
edn_to_md.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import edn_format
|
||||
import os
|
||||
import sys
|
||||
|
||||
def parse_edn_file(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
data = edn_format.loads(file.read())
|
||||
return data
|
||||
|
||||
def convert_to_markdown(data, output_dir):
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
|
||||
for i, item in enumerate(data):
|
||||
file_name = f"output_{i+1}.md"
|
||||
file_path = os.path.join(output_dir, file_name)
|
||||
|
||||
with open(file_path, 'w') as file:
|
||||
file.write("# Data Item\n\n")
|
||||
if isinstance(item, dict):
|
||||
for key, value in item.items():
|
||||
file.write(f"## {key}\n\n")
|
||||
file.write(f"{value}\n\n")
|
||||
else:
|
||||
file.write(f"{item}\n\n")
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python edn_to_markdown.py <input_edn_file>")
|
||||
sys.exit(1)
|
||||
|
||||
edn_file_path = sys.argv[1]
|
||||
output_dir = "output_markdown_files"
|
||||
|
||||
data = parse_edn_file(edn_file_path)
|
||||
|
||||
# Debugging output to inspect the structure of the data
|
||||
print("Parsed EDN data structure:")
|
||||
print(data)
|
||||
|
||||
convert_to_markdown(data, output_dir)
|
||||
print(f"Converted EDN data to Markdown files in '{output_dir}'")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user