Skip to content

Commit

Permalink
Update markdown_to_json.py
Browse files Browse the repository at this point in the history
  • Loading branch information
monk1337 authored Aug 11, 2024
1 parent 45b097e commit 9b87592
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions markdown_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,33 @@
def process_tasks(tasks_folder, json_folder):
# Create the JSON folder if it doesn't exist
os.makedirs(json_folder, exist_ok=True)

# Get a list of all markdown files in the tasks folder
md_files = [f for f in os.listdir(tasks_folder) if f.endswith('.md')]

for md_file in md_files:
# Construct full paths for markdown and json files
md_path = os.path.join(tasks_folder, md_file)
json_file = md_file.replace('.md', '.json')
json_path = os.path.join(json_folder, json_file)

# Check if JSON file needs to be created or updated
if not os.path.exists(json_path) or os.path.getmtime(md_path) > os.path.getmtime(json_path):
print(f"Processing {md_file}...")

try:
# Read the markdown file
with open(md_path, 'r', encoding='utf-8') as md_file:
markdown_content = md_file.read()

# Parse markdown to JSON
json_content = parse_markdown_to_json(markdown_content)

# Write the JSON content to file
with open(json_path, 'w', encoding='utf-8') as json_file:
json.dump(json_content, json_file, indent=2, ensure_ascii=False, separators=(',', ': '))
with open(json_path, 'w', encoding='utf-8', newline='\n') as json_file:
json.dump(json_content, json_file, indent=2, ensure_ascii=False)
json_file.write('\n') # Add a final newline



print(f"Successfully converted and saved {json_file}")
except MarkdownParsingError as e:
# Handle specific markdown parsing errors
Expand All @@ -51,6 +49,6 @@ def process_tasks(tasks_folder, json_folder):
# Define folder paths
tasks_folder = "tasks"
json_folder = "tasks-json"

# Run the main processing function
process_tasks(tasks_folder, json_folder)

0 comments on commit 9b87592

Please sign in to comment.