Beispiel #1
0
def history_scores():
    stu_id = request.get_json()['stuId']
    password = request.get_json()['password']
    try:
        zf_session, name, board_msg = s_login(stu_id, password, url)
    except Exception as e:
        print(e)
        raise APIException("error", str(e), 401)
    from ZfQueryMod.query import query_score
    from ZfQueryMod.gpa import average
    scores_list = query_score(stu_id, zf_session, url)
    if not scores_list:
        raise APIException("oops", "未进行教学评价", 403)
    data = {"scores": scores_list, "avg": average(scores_list)}
    return jsonify(data)
    def test_as_dict_returns_all_fields(self):
        error_code = 'testing_error_code'
        error_message = 'oh my god!'
        error_details = {'some extra info': 'goes here'}

        exception = APIException(
            error_code=error_code,
            error_message=error_message,
            error_details=error_details
        )

        data = exception.as_dict()

        assert data['error_code'] == error_code
        assert data['error_message'] == error_message
        assert data['error_details'] == error_details
Beispiel #3
0
    def putUpdateCustomers(self, ):
        '''
        Update one or more objects

        :returns: response from the API call
        :rType: CustomersModel 
        '''

        #prepare query string for API call
        queryBuilder = Configuration.BASEURI + "/Customers"

        #validate and preprocess url
        queryUrl = APIHelper.cleanUrl(queryBuilder)

        #prepare headers
        headers = {
            "User-Agent": "APIMATIC 2.0",
            "Accept": "application/json",
        }

        #prepare and invoke the API call request to fetch the response
        response = unirest.put(queryUrl, headers=headers)

        #Error handling using HTTP status codes
        if response.code < 200 and response.code > 206:  #200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code)

        return response.body
Beispiel #4
0
def login():
    stu_id = request.get_json()['stuId']
    password = request.get_json()['password']
    try:
        zf_session, name, board_msg = s_login(stu_id, password, url)
    except Exception as e:
        print(e)
        raise APIException("error", str(e), 401)
    return jsonify({'name': name, 'board_msg': board_msg})
Beispiel #5
0
def teaching_evaluate():
    stu_id = request.get_json()['stuId']
    password = request.get_json()['password']
    try:
        zf_session, name, board_msg = s_login(stu_id, password, url)
    except Exception as e:
        print(e)
        raise APIException("error", str(e), 403)
    from ZfQueryMod.teaching_evaluate import evaluate
    evaluate(stu_id, zf_session, url)
    return "ossas"
Beispiel #6
0
def get_course_table():
    stu_id = request.get_json()['stuId']
    password = request.get_json()['password']
    try:
        zf_session, name, board_msg = s_login(stu_id, password, url)
    except Exception as e:
        print(e)
        raise APIException("error", str(e), 403)
    from ZfQueryMod.query import course_table
    table = course_table(stu_id, zf_session, url)
    return jsonify(table)
Beispiel #7
0
def get_exams():
    stu_id = request.get_json()['stuId']
    password = request.get_json()['password']
    try:
        zf_session, name, board_msg = s_login(stu_id, password, url)
    except Exception as e:
        print(e)
        raise APIException("error", str(e), 403)
    from ZfQueryMod.query import query_exam
    table = query_exam(stu_id, zf_session, url)
    data = {'msg': table[0], 'exams': table[1]}
    return jsonify(data)
Beispiel #8
0
    def DeleteOneCustomers(self, pk):
        '''
        Delete one object

        :param pk: Required CustomerID 
        :type pk: string
        :returns: response from the API call
        :rType: CustomersModel 
        '''

        #prepare query string for API call
        queryBuilder = Configuration.BASEURI + "/Customers/{pk}"

        #process optional query parameters
        queryBuilder = APIHelper.appendUrlWithTemplateParameters(
            queryBuilder, {
                "pk": pk,
            })

        #validate and preprocess url
        queryUrl = APIHelper.cleanUrl(queryBuilder)

        #prepare headers
        headers = {
            "User-Agent": "APIMATIC 2.0",
            "Accept": "application/json",
        }

        #prepare and invoke the API call request to fetch the response
        response = unirest.delete(queryUrl, headers=headers)

        #Error handling using HTTP status codes
        if response.code < 200 and response.code > 206:  #200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code)

        return response.body
Beispiel #9
0
    def GetCustomers(self, filter=None):
        '''
        Get zero or more objects from table Customers

        :param filter: Optional Arbitrary search criteria 
        :type filter: string|null
        :returns: response from the API call
        :rType: CustomersModel 
        '''

        #prepare query string for API call
        queryBuilder = Configuration.BASEURI + "/Customers"

        #process optional query parameters
        queryBuilder = APIHelper.appendUrlWithQueryParameters(
            queryBuilder, {
                "filter": filter,
            })

        #validate and preprocess url
        queryUrl = APIHelper.cleanUrl(queryBuilder)

        #prepare headers
        headers = {
            "User-Agent": "APIMATIC 2.0",
            "Accept": "application/json",
        }

        #prepare and invoke the API call request to fetch the response
        response = unirest.get(queryUrl, headers=headers)

        #Error handling using HTTP status codes
        if response.code < 200 and response.code > 206:  #200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code)

        return response.body
    def test_as_dict_removes_empty_error_details(self):
        exception = APIException()

        data = exception.as_dict()
        assert 'error_details' not in data
Beispiel #11
0
        #validate and preprocess url
        queryUrl = APIHelper.cleanUrl(queryBuilder)

        #prepare headers
        headers = {
            "User-Agent" : "APIMATIC 2.0",
            "Accept" : "application/json",
        }

        #prepare and invoke the API call request to fetch the response
        response = unirest.get(queryUrl, headers=headers)

        #Error handling using HTTP status codes
        if response.code < 200 and response.code > 206: #200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code)     

        return response.body

    def postUpdateCarInfo(self,
                newOwner,
                odometer,
                $fieldParameters = None):
        '''
        TODO: type endpoint description here

        :param newOwner: Required The new owner of this car 
        :type newOwner: string
        :param odometer: Required Current kilometers reading from odometer 
        :type odometer: int
        :param fieldParameters:Additional optional form parameters are supported by this endpoint 
async def api_exception_handler(request):
    raise APIException()