class documentation

class SJTUQuestionnaire:

View In Hierarchy

An SJTU Questionnaire class for Object-Oriented Programming

Method __init__ Initialize an SJTU Questionnaire object
Method get_all_data 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_data 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_questionnaire_api_format The format of the SJTU Questionnaire API, currently supports SJTU Questionnaire API v1
Class Variable sjtu_questionnaire_api_format_url Undocumented
Instance Variable has_logger 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
def __init__(self, url_or_key, logger=None):

Initialize an SJTU Questionnaire object

Parameters
url_or_key:

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 NoneThe logger of the SJTU Questionnaire object, can be None if not provided
def get_all_data(self, params=None, sort='asc'):

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:strThe 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
ValueErrorIf either params or sort is invalid.
requests.exceptions.RequestExceptionIf the request fails.
def get_data(self, params=None, sort='asc'):

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 NoneThe parameters of the SJTU Questionnaire API, defaults to None (treated as an empty dict).
sort:strThe 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
ValueErrorIf either params or sort is invalid.
requests.exceptions.RequestExceptionIf the request fails.
Note
See get_all_data if you would like to get all the data without bothering about pagination.
sjtu_questionnaire_api_format: str =

The format of the SJTU Questionnaire API, currently supports SJTU Questionnaire API v1

sjtu_questionnaire_api_format_url: str =

Undocumented

has_logger: bool =

Whether the SJTU Questionnaire object has a logger

logger: logging.Logger or None =

The logger of the SJTU Questionnaire object, can be None if not provided

url: str =

The base URL of the SJTU Questionnaire API

def __log(self, msg, level=logging.DEBUG):

Undocumented

Parameters
msg:strUndocumented
level:intUndocumented