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 4221b55 commit 96c5af8
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions generate_markdown_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@

def generate_markdown_list(root_dir):
markdown_list = []
for subdir, dirs, files in os.walk(root_dir):
for subdir, _, files in os.walk(root_dir):
for file in files:
if file.endswith(".md"):
file_path = os.path.join(subdir, file)
print(f"Processing file: {file_path}") # Debugging
track, skill, module = get_levels(file_path)
title = get_header(file_path)
markdown_list.append({
"path": file_path,
"title": get_header(file_path),
"track": track,
"skill": skill,
"module": module
"module": module,
"title": title,
"path": file_path
})
print(f"Markdown files found: {len(markdown_list)}") # Debugging
return markdown_list

def get_header(file_path):
Expand All @@ -30,39 +29,28 @@ def get_header(file_path):

def get_levels(file_path):
parts = file_path.split(os.sep)
if len(parts) >= 4:
return parts[-4], parts[-3], parts[-2]
return None, None, None
track = parts[1] if len(parts) > 1 else None
skill = parts[2] if len(parts) > 2 else None
module = parts[3] if len(parts) > 3 else None
return track, skill, module

def save_to_csv(data, filename):
if not data:
print(f"No data to write to {filename}")
return
keys = data[0].keys()
keys = data[0].keys() if data else []
with open(filename, 'w', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, keys)
dict_writer.writeheader()
dict_writer.writerows(data)
print(f"CSV file saved: {filename}") # Debugging

def save_to_json(data, filename):
if not data:
print(f"No data to write to {filename}")
return
with open(filename, 'w') as f:
json.dump(data, f, indent=2)
print(f"JSON file saved: {filename}") # Debugging

def save_to_yaml(data, filename):
if not data:
print(f"No data to write to {filename}")
return
with open(filename, 'w') as f:
yaml.dump(data, f, default_flow_style=False)
print(f"YAML file saved: {filename}") # Debugging

if __name__ == "__main__":
root_dir = "path/to/your/markdown/files" # Make sure this path is correct
root_dir = "." # Asegúrate de estar en la raíz del repositorio
markdown_list = generate_markdown_list(root_dir)

save_to_csv(markdown_list, "markdown_files.csv")
Expand Down

0 comments on commit 96c5af8

Please sign in to comment.