class SJTUQuestionnaire:
An SJTU Questionnaire class for Object-Oriented Programming
| Method | __init__ |
Initialize an SJTU Questionnaire object |
| Method | get |
Get all the data of the questionnaire. This will send multiple requests to the server, and the data will be merged into a list of user answers. |
| Method | get |
Send a request to SJTU Questionnaire API. This is just a wrapper for requests.get. It is the developer's responsibility to check the validity, usually whether ret["success"] is True. |
| Class Variable | sjtu |
The format of the SJTU Questionnaire API, currently supports SJTU Questionnaire API v1 |
| Class Variable | sjtu |
Undocumented |
| Instance Variable | has |
Whether the SJTU Questionnaire object has a logger |
| Instance Variable | logger |
The logger of the SJTU Questionnaire object, can be None if not provided |
| Instance Variable | url |
The base URL of the SJTU Questionnaire API |
| Method | __log |
Undocumented |
Initialize an SJTU Questionnaire object
| Parameters | |
| url str If url_or_key starts with "https://wj.sjtu.edu.cn/api/v1/public/export/", it is assumed to be a URL. If url_or_key has length 32 and is a hexadecimal string, it is assumed to be a key of the SJTU Questionnaire API. The key will be converted to a URL using the sjtu_questionnaire_api_format class variable. | The URL of the SJTU Questionnaire API or the key of the SJTU Questionnaire API |
| logger:logging.Logger or None | The logger of the SJTU Questionnaire object, can be None if not provided |
Get all the data of the questionnaire. This will send multiple requests to the server, and the data will be merged into a list of user answers.
| Parameters | |
| params: dict or None Some values will be overridden, such as pageSize and current. | The parameters of the SJTU Questionnaire API, defaults to None (treated as an empty dict). |
sort:str | The sort of the SJTU Questionnaire API, defaults to "asc". It can be "asc" or "desc". |
| Returns | |
list For bad response by the server (determined by status code), an empty list [] will be returned, and the error will be logged. | All the data of the SJTU Questionnaire API |
| Raises | |
ValueError | If either params or sort is invalid. |
requests.exceptions.RequestException | If the request fails. |
Send a request to SJTU Questionnaire API. This is just a wrapper for requests.get. It is the developer's responsibility to check the validity, usually whether ret["success"] is True.
| Parameters | |
| params:dict or None | The parameters of the SJTU Questionnaire API, defaults to None (treated as an empty dict). |
sort:str | The sort of the SJTU Questionnaire API, defaults to "asc". It can be "asc" or "desc". |
| Returns | |
dict For bad response by the server (determined by status code), there will be no exception raised, but the error info will be logged to logger and returned as-is. | Response of the SJTU Questionnaire API |
| Raises | |
ValueError | If either params or sort is invalid. |
requests.exceptions.RequestException | If the request fails. |
| Note | |
See get_all_data if you would like to get all the data without bothering about pagination. | |
The format of the SJTU Questionnaire API, currently supports SJTU Questionnaire API v1