def get_download_url(self, auth: Dict): if self.multimedia: uri = "multimedia/media/{}".format(self.id) response = api(auth, uri)["ok"] return response.get("steamUrlPath", None) else: uri = "files/file/{}/downloadurl".format(self.id) response = api(auth, uri)["ok"] return response.get("data", None)
def announcements(self, auth: Dict, archived=False) -> Optional[List[Dict]]: """ Returns a list of announcements for a given module. The LumiNUS API provides 2 separate endpoints for archived and non-archived announcements. By default, announcements are archived after roughly 16 weeks (hence, the end of the semester) so most of the times, we should never need to access archived announcements. """ fields = ["title", "description", "displayFrom"] uri = "announcement/{}/{}?sortby=displayFrom%20ASC".format( "Archived" if archived else "NonArchived", self.id) response = api(auth, uri) if "error" in response: return None response = response["ok"] if "data" not in response: return None result = [] for announcement in response["data"]: if not all(key in announcement for key in fields): return None result.append({ "title": announcement["title"], "description": utils.remove_html_tags(announcement["description"]), "datetime": date_parse(announcement["displayFrom"]), }) return result
def weblectures(self, auth: Dict) -> Optional[List[Weblecture]]: """Get all weblectures for this mod""" uri_parent = "weblecture/?ParentID={}".format(self.id) parent_result = api(auth, uri_parent)["ok"] if "error" in parent_result: return None uri_children = "weblecture/{}/sessions/?sortby=createdDate".format( parent_result["id"]) children_result = api(auth, uri_children)["ok"] if not "data" in children_result or not isinstance( children_result["data"], list): return None return [ Weblecture.from_api(item, self.id) for item in children_result["data"] ]
def lessons(self, auth: Dict) -> Optional[List[Lesson]]: uri = "/lessonplan/Lesson/?ModuleID={}".format(self.id) response = api(auth, uri)["ok"] if "data" not in response: return None return [ Lesson.from_api(lesson_data, self.id) for lesson_data in response["data"] ]
def get_children(cls, auth: Dict, id: str, allow_upload: bool) -> Optional[List[File]]: """get children of file. If it fails, e.g. for CP4101 return None """ res = api(auth, "files/?ParentID={}".format(id)) if "error" in res: print("Failed to get children: {}".format(res['error'])) return None directory_children = res["ok"] directory_files = api( auth, "files/{}/file{}".format( id, "?populate=Creator" if allow_upload else ""), )["ok"] return [ cls.parse_child(file_data, allow_upload) for file_data in directory_children["data"] + directory_files["data"] ]
def files(self, auth: Dict): """get files associated with that lesson plan""" uri = "lessonplan/Activity/?populate=TargetAncestor&ModuleID={}&LessonID={}".format( self.module_id, self.id) response = api(auth, uri)["ok"] # NOTE items could also include links to weblectures etc, thus File.from_lesson(data) # could be None, filter those out if "data" in response and isinstance(response["data"], list): result = [File.from_lesson(data) for data in response["data"]] return [f for f in result if f] return None
def get_class_grps(auth, mod_id): print(auth) api_path = "user/Resource/" + mod_id + "/Group" response = api(auth, api_path) #print("\n") #print(mod_id) #print(response) #print("\n") try: data = response['ok']['data'] print(data) class_grps = [] for grp in data: if 'classNo' in grp: classNum = grp['classNo'] classId = grp['id'] class_grp = {'classNum': classNum, 'id': classId} class_grps.append(class_grp) return class_grps except KeyError: print("Not found")
def get_download_url(self, auth: Dict, session) -> Optional[str]: """obtains download url for given weblecture""" uri = "lti/Launch/panopto?context_id={}&resource_link_id={}".format( self.module_id, self.id) api_response = api(auth, uri)["ok"] if "launchURL" in api_response and "dataItems" in api_response: launch_url, dataItems = api_response["launchURL"], api_response[ "dataItems"] headers = {"Content-Type": "application/x-www-form-urlencoded"} dataItemsCombined = { item["key"]: item["value"] for item in dataItems } response = session.post(launch_url, headers=headers, data=dataItemsCombined) soup = BeautifulSoup(response.text, "html.parser") video = soup.find("meta", property="og:video") return video["content"] return None