Commit a4d933f3 authored by Alex's avatar Alex
Browse files

Implemented first working version (get courses by year)

parent 014f686a
from typing import List
import requests
from . import auth
from .courses import Courses, Course
from .resources import Resources, Course
MATERIALS_API_STATUS_URL = "https://api-materials.doc.ic.ac.uk/status"
......@@ -24,3 +24,11 @@ class Materials:
raise Exception("The Materials API is currently down.")
return Materials(auth.login(username, password))
def get_courses_for_year(self, academic_year: str) -> List[Course]:
"""
Returns a list of Courses that were available for the logged in
user during the given the academic_year string.
(e.g. 2122 for the year 2021/2022).
"""
return Courses.get_for_year(self._access_token, academic_year)
from typing import List
import requests
from . import auth
from .resources import Resources, Resource
class Course:
......@@ -9,6 +8,9 @@ class Course:
self.code = code
self.has_materials = has_materials
self.resources = resources
def __repr__(self) -> str:
return f"Course('{self.title}', code = {self.code})"
MATERIALS_API_COURSES_URL = "https://api-materials.doc.ic.ac.uk/courses"
......@@ -34,7 +36,7 @@ class Courses:
courses = []
for course in data:
resources = resources.Resources.get_resources_for_course(access_token, course["code"])
resources = Resources.get_resources_for_course(access_token, course["code"])
c = Course(course["title"], course["code"], course["has_materials"], resources=resources)
courses.append(c)
......
from typing import List
import requests
from enum import Enum
class ResourceType(Enum):
FILE = "file"
LINK = "link"
class Resource:
pass
def __init__(self, id: int, title: str, type: ResourceType, category: str, url: str, course_code: str):
self.id = id
self.title = title
self.type = type
self.category = category
self.url = url
self.course_code = course_code
def __repr__(self) -> str:
return f"Resource('{self.title}', type = {self.type}, category = '{self.category}')"
MATERIALS_API_RESOURCES_URL = "https://api-materials.doc.ic.ac.uk/resources"
......@@ -25,7 +42,14 @@ class Resources:
resources = []
for resource in data:
res = Resource()
res = Resource(
resource["id"],
resource["title"],
ResourceType(resource["type"]),
resource["category"],
resource["path"],
resource["course"]
)
resources.append(res)
return resources
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment