Skip to content

Commit

Permalink
Update generate_markdown_list.py
Browse files Browse the repository at this point in the history
  • Loading branch information
diegovelezg authored Jul 3, 2024
1 parent 8e23a75 commit d5cf3c1
Showing 1 changed file with 9 additions and 45 deletions.
54 changes: 9 additions & 45 deletions generate_markdown_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

def get_first_h2_from_markdown(md_content):
lines = md_content.split('\n')
Expand Down Expand Up @@ -84,50 +85,13 @@ def generate_markdown_list(root_dir):
records.append(record)
return records

root_dir = 'path_to_your_directory'
records = generate_markdown_list(root_dir)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python generate_markdown_list.py <root_directory>")
sys.exit(1)

# Now you can print or save `records` as needed
import json
print(json.dumps(records, indent=2))
root_dir = sys.argv[1]
records = generate_markdown_list(root_dir)


"""
import os
import yaml
import json
import pandas as pd
repo_path = '.'
markdown_files = []
for root, dirs, files in os.walk(repo_path):
for file in files:
if file.endswith('.md'):
full_path = os.path.join(root, file)
relative_path = os.path.relpath(full_path, repo_path)
# Leer el contenido del archivo y extraer el header1
with open(full_path, 'r', encoding='utf-8') as md_file:
for line in md_file:
if line.startswith('# '):
header1 = line.strip().lstrip('# ').strip()
break
else:
header1 = None # No se encontró un encabezado de nivel 1
markdown_files.append({'Path': relative_path, 'Header1': header1})
# Guardar en YAML
with open('markdown_files.yaml', 'w') as yaml_file:
yaml.dump(markdown_files, yaml_file, default_flow_style=False, allow_unicode=True)
# Guardar en JSON
with open('markdown_files.json', 'w') as json_file:
json.dump(markdown_files, json_file, indent=4, ensure_ascii=False)
# Guardar en CSV
df = pd.DataFrame(markdown_files)
df.to_csv('markdown_files.csv', index=False)
"""
import json
print(json.dumps(records, indent=2))

0 comments on commit d5cf3c1

Please sign in to comment.