Ejemplo n.º 1
0
def get_enrollments():
    from auth import get_user, get_userid
    if not get_user():
        return []
    if get_user() == "B3yGtjkIFz":
        return ["ENGL 999 001 20135", "SPAN 999 001 20135"]
    if "enrollments" in session:
        return session.get('enrollments')
    url = "https://ws.byu.edu/rest/v1.0/academic/registration/studentschedule/" + get_userid(
    ) + "/" + getCurrentSem()
    headerVal = byu_ws_sdk.get_http_authorization_header(
        BYU_WS_ID,
        BYU_SHARED_SECRET,
        byu_ws_sdk.KEY_TYPE_API,
        byu_ws_sdk.ENCODING_NONCE,
        actor=get_user(),
        url=url,
        httpMethod=byu_ws_sdk.HTTP_METHOD_GET,
        actorInHash=True)
    res = requests.get(url, headers={'Authorization': headerVal})
    courses = []
    try:
        content = json.loads(res.content)['WeeklySchedService']['response']
    except ValueError:
        content = {"schedule_table": []}
    for course in content["schedule_table"]:
        courses.append(" ".join(
            (course['course'], course['section'], content['year_term'])))
    session['enrollments'] = courses
    return courses
Ejemplo n.º 2
0
def get_enrollments():
    from auth import get_user, get_userid

    if not get_user():
        return []
    if get_user() == "B3yGtjkIFz":
        return ["ENGL 999 001 20135", "SPAN 999 001 20135"]
    if "enrollments" in session:
        return session.get("enrollments")
    url = "https://ws.byu.edu/rest/v1.0/academic/registration/studentschedule/" + get_userid() + "/" + getCurrentSem()
    headerVal = byu_ws_sdk.get_http_authorization_header(
        BYU_WS_ID,
        BYU_SHARED_SECRET,
        byu_ws_sdk.KEY_TYPE_API,
        byu_ws_sdk.ENCODING_NONCE,
        actor=get_user(),
        url=url,
        httpMethod=byu_ws_sdk.HTTP_METHOD_GET,
        actorInHash=True,
    )
    res = requests.get(url, headers={"Authorization": headerVal})
    courses = []
    try:
        content = json.loads(res.content)["WeeklySchedService"]["response"]
    except ValueError:
        content = {"schedule_table": []}
    for course in content["schedule_table"]:
        courses.append(" ".join((course["course"], course["section"], content["year_term"])))
    session["enrollments"] = courses
    return courses
Ejemplo n.º 3
0
    def get_enrollments(self, username, userid):
        from config import APIHOST, YT_SERVICE, BYU_WS_ID, BYU_SHARED_SECRET
        import json, byu_ws_sdk, requests
        import xml.etree.ElementTree as ET
        from helpers import getCurrentSem

        url="https://ws.byu.edu/rest/v1.0/academic/registration/studentschedule/"+userid+"/"+getCurrentSem()
        headerVal = byu_ws_sdk.get_http_authorization_header(BYU_WS_ID, BYU_SHARED_SECRET, byu_ws_sdk.KEY_TYPE_API,byu_ws_sdk.ENCODING_NONCE,actor=username,url=url,httpMethod=byu_ws_sdk.HTTP_METHOD_GET,actorInHash=True)
        res = requests.get(url, headers={'Authorization': headerVal})
        """ A haiku:

              Success gives JSON,
              but errors give XML.
             Pray this handles both.  """
        try:
            return json.loads(res.text)
        except ValueError:
            try:
                root = ET.fromstring(res.text)
                errMsg = root.\
                   find('fault/value/*/member/[name="faultString"]'
                        '/value/string')
                if errMsg is None:
                    raise res.text

                raise Exception(errMsg.text)
            except ET.ParseError:
                raise res.text
Ejemplo n.º 4
0
def api_key_header(url, method, actor_net_id):
    return byu_ws.get_http_authorization_header(config['api_key'],
                                                config['shared_secret'],
                                                byu_ws.KEY_TYPE_API,
                                                byu_ws.ENCODING_NONCE,
                                                url=url,
                                                actor=actor_net_id,
                                                httpMethod=method)
Ejemplo n.º 5
0
def api_key_header(url, method, actor_net_id):
    return byu_ws.get_http_authorization_header(
            config.api_key, config.shared_secret,
            byu_ws.KEY_TYPE_API, byu_ws.ENCODING_NONCE,
            url=url, actor=actor_net_id, httpMethod=method)
Ejemplo n.º 6
0
def get_enrollments(username, userid):
    url="https://ws.byu.edu/rest/v1.0/academic/registration/studentschedule/"+userid+"/"+getCurrentSem()
    headerVal = byu_ws_sdk.get_http_authorization_header(BYU_WS_ID, BYU_SHARED_SECRET, byu_ws_sdk.KEY_TYPE_API,byu_ws_sdk.ENCODING_NONCE,actor=username,url=url,httpMethod=byu_ws_sdk.HTTP_METHOD_GET,actorInHash=True)
    res=requests.get(url, headers={'Authorization': headerVal})
    return res