Beispiel #1
0
def modules(auth: Dict,
            current_term_only: bool = False) -> Result[List[Optional[Module]]]:
    """ returns list of modules that user with given authorization is reading
    """
    from pyfluminus.structs import Module

    response = api(auth, "module")["ok"]
    if "data" in response:
        return Result(
            [Module.from_api(mod_data) for mod_data in response["data"]])
    return ErrorResult(ErrorTypes.UnexpectedResponse, response)
Beispiel #2
0
def current_term(auth: Dict) -> Result:
    """returns info about current term
    e.g.: {term: "1820", description: "2018/2019 Semester 2"}
    """
    response = api(auth,
                   "/setting/AcademicWeek/current?populate=termDetail")["ok"]
    if "termDetail" in response:
        return Result({
            "term": response["termDetail"]["term"],
            "description": response["termDetail"]["description"],
        })
    return ErrorResult(ErrorTypes.UnexpectedResponse, response)
Beispiel #3
0
def get_announcements(auth: Dict, module_id: str, archive: bool) -> Result:
    fields = ["title", "description", "displayFrom"]
    uri = "announcement/{}/{}?sortby=displayFrom%20ASC".format(
        "Archived" if archive else "NonArchived", module_id)
    response = api(auth, uri)["ok"]
    if "data" in response:
        result_data = []
        for announcement in response["data"]:
            if not all(key in announcement for key in fields):
                return ErrorResult(ErrorTypes.UnexpectedResponse, response)
            result_data.append({
                "title":
                announcement["title"],
                "description":
                utils.remove_html_tags(announcement["description"]),
                "datetime":
                date_parse(announcement["displayFrom"]),
            })
        return Result(result_data)
    return ErrorResult(ErrorTypes.Error)
Beispiel #4
0
def name(auth: Dict) -> Result:
    response = api(auth, "user/Profile")["ok"]
    if "userNameOriginal" in response:
        name = response["userNameOriginal"].title()
        return Result(data=name)
    return ErrorResult(error_type=ErrorTypes.Error)