Exemplo n.º 1
0
def get_coursetables(year, semester):
    # See Gist for more infomation.
    # https://gist.github.com/hearsilent/a2570371cc6aa7db97bb

    weekdays = {"M": "Monday", "T": "Tuesday", "W": "Wednesday",
                "R": "Thursday", "F": "Friday", "S": "Saturday",
                "H": "Sunday"
                }

    # Restore cookies
    s = stateless_auth.get_requests_session_with_cookies()

    classes = cache.ap_query(
        s, "ag222", {"arg01": year, "arg02": semester, "uid": "1101133117"}, g.username)

    # No Content
    if not classes:
        return jsonify(status=const.no_content, messages="學生目前無選課資料", coursetables=classes)

    coursetables = {}
    for c in classes:
        weekday = weekdays[c["date"]["weekday"]]
        if not weekday in coursetables:
            coursetables[weekday] = []

        coursetables[weekday].append(c)

    return jsonify(status=const.ok, messages="", coursetables=coursetables)
Exemplo n.º 2
0
def query_post():
    if request.method == "POST":
        fncid = request.form['fncid']
        arg01 = request.form['arg01'] if 'arg01' in request.form else None
        arg02 = request.form['arg02'] if 'arg02' in request.form else None
        arg03 = request.form['arg03'] if 'arg03' in request.form else None
        arg04 = request.form['arg04'] if 'arg04' in request.form else None

        # if 'c' not in session:
        #    return "false"
        # Restore cookies
        s = requests.session()
        set_cookies(s, session['c'])

        query_content = cache.ap_query(
            s, fncid, {"arg01": arg01, "arg02": arg02, "arg03": arg03, "arg04": arg04}, session['username'])

        if fncid == "ag222":
            return json.dumps(query_content)
        elif fncid == "ag008":
            return json.dumps(query_content)
        else:
            return json.dumps(query_content)

    return render_template("query.html")
Exemplo n.º 3
0
def query_post():
    if request.method == "POST":
        fncid = request.form['fncid']
        arg01 = request.form['arg01'] if 'arg01' in request.form else None
        arg02 = request.form['arg02'] if 'arg02' in request.form else None
        arg03 = request.form['arg03'] if 'arg03' in request.form else None
        arg04 = request.form['arg04'] if 'arg04' in request.form else None

        # if 'c' not in session:
        #    return "false"
        # Restore cookies
        s = requests.session()
        set_cookies(s, session['c'])

        query_content = cache.ap_query(s, fncid, {
            "arg01": arg01,
            "arg02": arg02,
            "arg03": arg03,
            "arg04": arg04
        }, session['username'])

        if fncid == "ag222":
            return json.dumps(query_content)
        elif fncid == "ag008":
            return json.dumps(query_content)
        else:
            return json.dumps(query_content)

    return render_template("query.html")
Exemplo n.º 4
0
def get_score(year, semester):
    # Restore cookies
    s = stateless_auth.get_requests_session_with_cookies()

    scores = cache.ap_query(
        s, "ag008", {"arg01": year, "arg02": semester, "arg03": g.username}, g.username)

    if not scores:
        return jsonify(status=const.no_content, messages="目前無學生個人成績資料", scores={})

    return jsonify(status=const.ok, messages="", scores=scores)
Exemplo n.º 5
0
def _get_user_info(session):
    """Get user info

    return: `lxml.etree._Element`
    """

    content = cache.ap_query(session, "ag003", {}, "", expire=AP_QUERY_USER_EXPIRE)

    root = etree.HTML(content)

    return root
Exemplo n.º 6
0
def _get_user_info(session):
    """Get user info

    return: `lxml.etree._Element`
    """

    content = cache.ap_query(session,
                             "ag003", {},
                             g.username,
                             expire=AP_QUERY_USER_EXPIRE)

    root = etree.HTML(content)

    return root
Exemplo n.º 7
0
def query_post():
    fncid = request.form['fncid']
    arg01 = request.form['arg01'] if 'arg01' in request.form else None
    arg02 = request.form['arg02'] if 'arg02' in request.form else None
    arg03 = request.form['arg03'] if 'arg03' in request.form else None
    arg04 = request.form['arg04'] if 'arg04' in request.form else None

    # Restore cookies
    s = stateless_auth.get_requests_session_with_cookies()

    query_content = cache.ap_query(
        s, fncid, {"arg01": arg01, "arg02": arg02,
                   "arg03": arg03, "arg04": arg04}, g.username)

    if fncid == "ag222":
        return json.dumps(query_content)
    elif fncid == "ag008":
        return json.dumps(query_content)
    else:
        return json.dumps(query_content)