-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_existing_course.py
More file actions
61 lines (47 loc) Β· 1.88 KB
/
fix_existing_course.py
File metadata and controls
61 lines (47 loc) Β· 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
"""
Script to fix existing courses by adding missing index fields
"""
import json
import os
from pathlib import Path
def fix_existing_course(course_name: str):
"""Fix an existing course by adding index fields"""
course_dir = Path("courses") / course_name
course_file = course_dir / "course_structure.json"
if not course_file.exists():
print(f"β Course file not found: {course_file}")
return False
print(f"π§ Fixing course: {course_name}")
# Load the course data
with open(course_file, "r") as f:
course_data = json.load(f)
# Add index fields
sections = course_data.get("sections", [])
print(f"π Found {len(sections)} sections")
for section_idx, section in enumerate(sections[:7], 1):
section["index"] = section_idx
subsections = section.get("subsections", [])
print(f" π Section {section_idx}: {section['name']} - {len(subsections)} subsections")
for sub_idx, subsection in enumerate(subsections[:10], 1):
subsection["index"] = sub_idx
concepts = subsection.get("concepts", [])
print(f" π Subsection {sub_idx}: {subsection['name']} - {len(concepts)} concepts")
for concept_idx, concept in enumerate(concepts[:10], 1):
concept["index"] = concept_idx
# Save the fixed course data
with open(course_file, "w") as f:
json.dump(course_data, f, indent=2)
print(f"β
Course {course_name} fixed successfully!")
return True
def main():
"""Main function"""
print("π§ Course Fixer Script")
print("=" * 30)
# Fix the existing learn_C course
if fix_existing_course("learn_C"):
print("\nπ All courses fixed successfully!")
else:
print("\nβ Failed to fix courses")
if __name__ == "__main__":
main()