r3hab commited on
Commit
94ec996
·
verified ·
1 Parent(s): c9a5da9

Upload 30 files

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -3,24 +3,27 @@ import os
3
 
4
  app = FastAPI()
5
 
6
- NOTES_DIR = "notes/" # Base directory for notes
7
- SYLLABUS_PATH = os.path.join(NOTES_DIR, "syllabus", "syllabus.md")
8
-
9
 
 
10
  @app.get("/syllabus/")
11
  async def get_syllabus():
12
- if not os.path.exists(SYLLABUS_PATH):
 
13
  raise HTTPException(status_code=404, detail="Syllabus file not found")
14
 
15
- with open(SYLLABUS_PATH, "r", encoding="utf-8") as file:
16
  content = file.read()
17
  return {"content": content}
18
 
 
19
  @app.get("/subjects/")
20
  async def list_subjects():
21
  subjects = [d for d in os.listdir(NOTES_DIR) if os.path.isdir(os.path.join(NOTES_DIR, d))]
22
  return {"subjects": subjects}
23
 
 
24
  @app.get("/subjects/{subject}/units/")
25
  async def list_units(subject: str):
26
  subject_path = os.path.join(NOTES_DIR, subject)
@@ -30,11 +33,12 @@ async def list_units(subject: str):
30
  units = [f for f in os.listdir(subject_path) if f.endswith(".md")]
31
  return {"units": units}
32
 
33
- @app.get("/subjects/{subject}/units/{unit}/")
34
- async def get_unit(subject: str, unit: str):
 
35
  unit_path = os.path.join(NOTES_DIR, subject, unit)
36
  if not os.path.exists(unit_path):
37
- raise HTTPException(status_code=404, detail="Unit not found")
38
 
39
  with open(unit_path, "r", encoding="utf-8") as file:
40
  content = file.read()
 
3
 
4
  app = FastAPI()
5
 
6
+ # Define the directory where notes are stored
7
+ NOTES_DIR = "notes"
 
8
 
9
+ # Endpoint to fetch the syllabus
10
  @app.get("/syllabus/")
11
  async def get_syllabus():
12
+ syllabus_path = os.path.join(NOTES_DIR, "SYLLABUS", "syllabus.md")
13
+ if not os.path.exists(syllabus_path):
14
  raise HTTPException(status_code=404, detail="Syllabus file not found")
15
 
16
+ with open(syllabus_path, "r", encoding="utf-8") as file:
17
  content = file.read()
18
  return {"content": content}
19
 
20
+ # Endpoint to list all subjects (directories)
21
  @app.get("/subjects/")
22
  async def list_subjects():
23
  subjects = [d for d in os.listdir(NOTES_DIR) if os.path.isdir(os.path.join(NOTES_DIR, d))]
24
  return {"subjects": subjects}
25
 
26
+ # Endpoint to list all units for a given subject
27
  @app.get("/subjects/{subject}/units/")
28
  async def list_units(subject: str):
29
  subject_path = os.path.join(NOTES_DIR, subject)
 
33
  units = [f for f in os.listdir(subject_path) if f.endswith(".md")]
34
  return {"units": units}
35
 
36
+ # Endpoint to fetch the content of a specific unit
37
+ @app.get("/subjects/{subject}/units/{unit}")
38
+ async def get_unit_content(subject: str, unit: str):
39
  unit_path = os.path.join(NOTES_DIR, subject, unit)
40
  if not os.path.exists(unit_path):
41
+ raise HTTPException(status_code=404, detail="Unit file not found")
42
 
43
  with open(unit_path, "r", encoding="utf-8") as file:
44
  content = file.read()