API Reference¶
The following section outlines the API of pymyku.
Client¶
- deffetch_announce
- deffetch_enroll
- deffetch_gpax
- deffetch_grades
- deffetch_group_course
- deffetch_schedule
- deffetch_student_address
- deffetch_student_education
- deffetch_student_personal
- defget
- defget_enrolled_subjects
- defget_gpax
- defget_grades
- defget_group_course
- defget_total_credit
- defheaders
- definitialize
- deflogin
- defreset
- defsearch_section_detail
- defsearch_subject
- defsearch_subject_open
- defvalid_response
- class pymyku.Client(username, password)¶
Bases:
pymyku.type.ClientTypeRepresents a client connection that connects to MyKU. This class is used to interact with the MyKU API. The client is initialized with a username and password and will login to MyKU automatically.
- property login_response¶
Recent login response.
- Returns
Response from the login request. Represented by
pymyku.attribute.FetchedResponses.LOGIN_RESPONSE- Return type
- property access_token¶
Recent access token from the login response.
- Returns
Access token. Represented by
pymyku.attribute.Token.ACCESS_TOKEN- Return type
- property schedule_response¶
Recent schedule response.
- Returns
Response from the schedule request. Represented by
pymyku.attribute.FetchedResponses.SCHEDULE_RESPONSE- Return type
- property academic_year¶
Current academic year.
- Returns
Current academic year. Represented by
pymyku.attribute.Schedule.ACADEMIC_YEAR- Return type
Optional[str]
- property semester¶
Current semester.
- Returns
Current semester. Represented by
pymyku.attribute.Schedule.SEMESTER- Return type
Optional[str]
- property user_data¶
Return the user data extracted form login response.
- Returns
User data. Represented by
pymyku.attribute.User- Return type
- property student_data¶
Return the student data extracted form login response.
- Returns
Student data. Represented by
pymyku.attribute.Student- Return type
- property std_code¶
Return the student code extracted from the login response.
- Returns
Student code. Represented by
pymyku.attribute.Student.STD_CODE- Return type
- valid_response(response, to_json=True)¶
If the response is not 200, check if the error is due to an expired token. If so, reset the token and raise an error. Otherwise, raise the error
- Parameters
- Returns
Return the response if the response is 200. Otherwise, raise the error.
- Return type
- Raises
exception.TokenExpired – If the response is due to an expired token.
exception.HTTPError – If the response is not 200.
- initialize()¶
Initialize the client by logging in and fetch user data.
login()will be called to fetch login data. After that,fetch_schedule()will be called to fetch schedule data.Affected attributes:
login_response,access_token,schedule_response,academic_yearandsemester
- reset()¶
Reset the client attributes.
Affected attributes:
login_response,access_token,schedule_response,academic_yearandsemester
- headers()¶
Return the headers for the requests.
- Returns
The headers for the requests containing
pymyku.constant.APP_KEYandaccess_token.- Return type
- login()¶
Login to MyKu and fetch user data.
API: https://myapi.ku.th/auth/login
- Returns
Response object from the login request. Represented by
pymyku.attribute.FetchedResponses.LOGIN_RESPONSE- Return type
- fetch_schedule(as_response=False)¶
Send GET request to MyKU common/getschedule API.
API: https://myapi.ku.th/common/getschedule
- Parameters
as_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False
- Returns
Response from the request. Represented by
pymyku.attribute.FetchedResponses.SCHEDULE_RESPONSE- Return type
- fetch_announce(academic_year=None, semester=None, as_response=False)¶
Send GET request to MyKU advisor/getAnnounceStd API.
- fetch_grades(as_response=False)¶
Send GET request to MyKU std-profile/checkGrades API.
- fetch_group_course(as_response=False)¶
Send GET request to MyKU std-profile/getGroupCourse API.
- fetch_student_address(as_response=False)¶
Send GET request to MyKU std-profile/getStdAddress API.
- fetch_student_personal(as_response=False)¶
Send GET request to MyKU std-profile/getStdPersonal API.
- fetch_student_education(as_response=False)¶
Send GET request to MyKU std-profile/getStdEducation API.
- fetch_gpax(as_response=False)¶
Send GET request to MyKU stddashboard/gpax API.
- fetch_enroll(academic_year=None, semester=None, as_response=False)¶
Send GET request to MyKU enroll/searchEnrollResult API.
API: https://myapi.ku.th/enroll/searchEnrollResult
- Parameters
academic_year (Optional[Union[str, int]], optional) – Academic year, if not provided, will use the current academic year. Represented by
pymyku.attribute.Schedule.ACADEMIC_YEARsemester (Optional[Union[str, int]], optional) – Semester, if not provided, will use the current semester. Represented by
pymyku.attribute.Schedule.SEMESTERas_response (Optional[bool]) – Return as Response object if True, otherwise dict, by default False
- Returns
Response from the request.
- Return type
- search_subject(query)¶
Query subject with subject id by sending GET request to MyKU enroll/searchSubjectOpenEnr API.
API: https://myapi.ku.th/enroll/searchSubjectOpenEnr
- Parameters
query (str) – Subject id or name to query. (At least 3 characters), e.g. ‘013’, ‘01355119’, ‘eng’ or ‘english’
- Returns
List of subject dicts.
- Return type
- Raises
ValueError – The query is less than 3 characters long.
exception.HTTPError – The request is not successful.
- search_subject_open(subject_id, section='', campus_code='')¶
Query subject enrollment info (All section) of current semester by sending GET request to MyKU enroll/openSubjectForEnroll API.
API: https://myapi.ku.th/enroll/openSubjectForEnroll
- Parameters
- Returns
List of subject’s opening section.
- Return type
- Raises
Value – The subject_id is less than 3 characters long.
exception.HTTPError – The request is not successful.
- search_section_detail(subject_id)¶
Send GET request to MyKU enroll/searchSectionDetail API.
- get(attr)¶
Get any value from MyKU client. (login response and schedule response) Use enums from pymyku.attribute as key to get value.
- get_group_course()¶
Send GET request to MyKU std-profile/getGroupCourse API and return the result.
- Returns
List of group course dicts (timetable).
- Return type
List[dict]
- Raises
exception.TokenExpired – The token is expired.
exception.HTTPError – The request is not successful.
- get_gpax()¶
Send GET request to MyKU std-profile/getGPAX API and return the gpax.
- Returns
GPAX.
- Return type
- Raises
exception.TokenExpired – The token is expired.
exception.HTTPError – The request is not successful.
- get_total_credit()¶
Send GET request to MyKU std-profile/getTotalCredit API and return the total credit.
- Returns
Total credit.
- Return type
- Raises
exception.TokenExpired – The token is expired.
exception.HTTPError – The request is not successful.
- get_grades(key='subject_code')¶
Fetch grades for each subjects in all semesters.
- Parameters
key (str) – Subject key from the response. Can be subject_code or subject_name_en. Otherwise, subject_code will be used. Defaults to “subject_code”.
- Returns
Dict of grades for each subjects in all semesters.
- Return type
- Raises
exception.TokenExpired – The token is expired.
exception.HTTPError – The request is not successful.
- get_enrolled_subjects(academic_year=None, semester=None)¶
Get enrolled subjects in a specific semester.
- Parameters
academic_year (Optional[Union[str, int]], optional) – Academic year, if not provided, will use the current academic year. Represented by
pymyku.attribute.Schedule.ACADEMIC_YEARsemester (Optional[Union[str, int]], optional) – Semester, if not provided, will use the current semester. Represented by
pymyku.attribute.Schedule.SEMESTER
- Returns
List of enrolled subjects.
- Return type
List[dict]
Requests¶
- pymyku.requests.get(url, params=None, **kwargs)¶
Sends a GET request.
- Parameters
url – URL for the new
Requestobject.params – (optional) Dictionary, list of tuples or bytes to send in the query string for the
Request.**kwargs – Optional arguments that
requesttakes.
- Returns
Responseobject- Return type
- pymyku.requests.post(url, data=None, json=None, **kwargs)¶
Sends a POST request.
- Parameters
url – URL for the new
Requestobject.data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the
Request.json – (optional) A JSON serializable Python object to send in the body of the
Request.**kwargs – Optional arguments that
requesttakes.
- Returns
Responseobject- Return type
- pymyku.requests.login(username, password)¶
Send POST request to MyKU auth/login API.
- pymyku.requests.logout(access_token='', login_response={}, client=None)¶
Send POST request to MyKU auth/logout API.
I am uncertain that this request method will work properly.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/auth/logout
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENlogin_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from auth/logout API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_schedule(access_token='', user_type='', campus_code='', faculty_code='', major_code='', student_status_code='', login_response={}, client=None)¶
Send GET request to MyKU common/getschedule API.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/common/getschedule
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENuser_type (Optional[str]) – ‘userType’ attribute from login response, Represented by
pymyku.attribute.User.USER_TYPEcampus_code (Optional[str]) – ‘campusCode’ attribute from login response, Represented by
pymyku.attribute.Student.CAMPUS_CODE, e.g. ‘B’ , e.g. ‘B’faculty_code (Optional[str]) – ‘facultyCode’ attribute from login response, Represented by
pymyku.attribute.Student.FACULTY_CODEmajor_code (Optional[str]) – ‘majorCode’ attribute from login response, Represented by
pymyku.attribute.Student.MAJOR_CODEstudent_status_code (Optional[str]) – ‘studentStatusCode’ attribute from login response, Represented by
pymyku.attribute.Student.STUDENT_STATUS_CODElogin_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from common/getschedule API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_group_course(access_token='', std_id='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)¶
Send GET request to MyKU std-profile/getGroupCourse API.
Assigning only (login_response and schedule_response) or client is acceptable.
API: https://myapi.ku.th/std-profile/getGroupCourse
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_id (Optional[str]) – ‘stdId’ attribute from login response, Represented by
pymyku.attribute.Student.STD_ID, e.g. ‘20xxxx’academic_year (Optional[str]) – ‘academicYr’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.ACADEMIC_YEAR, e.g. ‘2565’semester (Optional[str]) – ‘semester’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.SEMESTER, e.g. ‘0’ for summer, ‘1’ for first semester and ‘2’ for second semester.login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEschedule_response (Optional[Union[Response, dict]]) – Schedule response from
get_schedule(), Represented bypymyku.attribute.FetchedResponses.SCHEDULE_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from std-profile/getGroupCourse API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_check_grades(access_token='', std_code='', login_response={}, client=None)¶
Send GET request to MyKU std-profile/checkGrades API.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/std-profile/checkGrades
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_code (Optional[str]) – ‘stdCode’ attribute from login response, Represented by
pymyku.attribute.Student.STD_CODE, e.g. ‘64xxxxxxxx’login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from std-profile/checkGrades API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_gpax(access_token='', std_id='', login_response={}, client=None)¶
Send GET request to MyKU stddashboard/gpax API.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/stddashboard/gpax
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_id (Optional[str]) – ‘stdId’ attribute from login response, Represented by
pymyku.attribute.Student.STD_ID, e.g. ‘20xxxx’login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from stddashboard/gpax API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_announce(access_token='', std_id='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)¶
Send GET request to MyKU advisor/getAnnounceStd API.
Assigning only (login_response and schedule_response) or client is acceptable.
API: https://myapi.ku.th/advisor/getAnnounceStd
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_id (Optional[str]) – ‘stdId’ attribute from login response, Represented by
pymyku.attribute.Student.STD_ID, e.g. ‘20xxxx’academic_year (Optional[str]) – ‘academicYr’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.ACADEMIC_YEAR, e.g. ‘2565’semester (Optional[str]) – ‘semester’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.SEMESTER, e.g. ‘0’ for summer, ‘1’ for first semester and ‘2’ for second semester.login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEschedule_response (Optional[Union[Response, dict]]) – Schedule response from
get_schedule(), Represented bypymyku.attribute.FetchedResponses.SCHEDULE_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from advisor/getAnnounceStd API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.search_enroll(access_token='', std_id='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)¶
Send GET request to MyKU enroll/searchEnrollResult API.
Assigning only (login_response and schedule_response) or client is acceptable.
API: https://myapi.ku.th/enroll/searchEnrollResult
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_id (Optional[str]) – ‘stdId’ attribute from login response, Represented by
pymyku.attribute.Student.STD_ID, e.g. ‘20xxxx’academic_year (Optional[str]) – ‘academicYr’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.ACADEMIC_YEAR, e.g. ‘2565’semester (Optional[str]) – ‘semester’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.SEMESTER, e.g. ‘0’ for summer, ‘1’ for first semester and ‘2’ for second semester.login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEschedule_response (Optional[Union[Response, dict]]) – Schedule response from
get_schedule(), Represented bypymyku.attribute.FetchedResponses.SCHEDULE_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from enroll/searchEnrollResult API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_student_personal(access_token='', std_id='', login_response={}, client=None)¶
Send GET request to MyKU std-profile/getStdPersonal API.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/std-profile/getStdPersonal
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_id (Optional[str]) – ‘stdId’ attribute from login response, Represented by
pymyku.attribute.Student.STD_ID, e.g. ‘20xxxx’login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from std-profile/getStdPersonal API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_student_education(access_token='', std_id='', login_response={}, client=None)¶
Send GET request to MyKU std-profile/getStdEducation API.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/std-profile/getStdEducation
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_id (Optional[str]) – ‘stdId’ attribute from login response, Represented by
pymyku.attribute.Student.STD_ID, e.g. ‘20xxxx’login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from std-profile/getStdEducation API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.get_student_address(access_token='', std_id='', login_response={}, client=None)¶
Send GET request to MyKU std-profile/getStdAddress API.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/std-profile/getStdAddress
- Parameters
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENstd_id (Optional[str]) – ‘stdId’ attribute from login response, Represented by
pymyku.attribute.Student.STD_ID, e.g. ‘20xxxx’login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from std-profile/getStdAddress API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.search_subject(query, access_token='', login_response={}, client=None)¶
Send GET request to MyKU enroll/searchSubjectOpenEnr API.
Assigning only login_response or client is acceptable.
API: https://myapi.ku.th/enroll/searchSubjectOpenEnr
- Parameters
query (str) – Subject id or name to query. (At least 3 characters), e.g. ‘013’, ‘01355119’, ‘eng’ or ‘english’
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENlogin_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from enroll/searchSubjectOpenEnr API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.search_subject_open(query, section='', access_token='', campus_code='', academic_year='', semester='', login_response={}, schedule_response={}, client=None)¶
Send GET request to MyKU enroll/openSubjectForEnroll API.
Assigning only (login_response and schedule_response) or client is acceptable.
API: https://myapi.ku.th/enroll/openSubjectForEnroll
- Parameters
query (str) – Full subject id, e.g. ‘01355119’ or ‘01355119-64’
section (Optional[str]) – Section of the subject, e.g. ‘1’
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENcampus_code (Optional[str]) – ‘campusCode’ attribute from login response, Represented by
pymyku.attribute.Student.CAMPUS_CODE, e.g. Campus code, ‘B’ for Bang Khen, ‘C’ for Sakolkorn, ‘I’ for affiliated institute, ‘K’ for Kamphaeng Saen, ‘P’ for Suphanburi.academic_year (Optional[str]) – ‘academicYr’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.ACADEMIC_YEAR, e.g. ‘2565’semester (Optional[str]) – ‘semester’ attribute from schedule response, Represented by
pymyku.attribute.Schedule.SEMESTER, e.g. ‘0’ for summer, ‘1’ for first semester and ‘2’ for second semester.login_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEschedule_response (Optional[Union[Response, dict]]) – Schedule response from
get_schedule(), Represented bypymyku.attribute.FetchedResponses.SCHEDULE_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from enroll/openSubjectForEnroll API.
- Return type
- Raises
ValueError – Required parameters are missing.
- pymyku.requests.search_section_detail(section_id, access_token='', login_response={}, client=None)¶
Send GET request to MyKU enroll/searchSectionDetail API.
API: https://myapi.ku.th/enroll/searchSectionDetail
- Parameters
section_id (str) – Section id. e.g. ‘186426’
access_token (Optional[str]) – ‘accesstoken’ from login response, Represented by
pymyku.attribute.Token.ACCESS_TOKENlogin_response (Optional[Union[Response, dict]]) – Login response from login request, can be obtained from
login()Represented bypymyku.attribute.FetchedResponses.LOGIN_RESPONSEclient (Optional[ClientType]) – Initialized
pymyku.Clientobject
- Returns
Response object from enroll/searchSectionDetail API.
- Return type
- Raises
ValueError – Required parameters are missing.
Utilities¶
- pymyku.utils.response_to_json(response)¶
Convert response to json. Do nothing if response is already dictionary
- pymyku.utils.extract(response, attr)¶
Extract any value from login response or schedule response. Use enums from pymyku.attribute as key to get value.
- pymyku.utils.get_raise(dictionary, key, dict_name=None)¶
Raise ValueError if key is not found in dictionary.
- Parameters
- Returns
Value of the key.
- Return type
Any
- Raises
ValueError – If key is not found in dictionary.
- pymyku.utils.extract_user_data(login_response)¶
Extract user data from login response.
- Parameters
login_response (Union[Response, dict]) – The response of the login request.
- Returns
User data. Represented by
pymyku.attribute.User- Return type
- Raises
ValueError – If user data is not found.
- pymyku.utils.extract_student_data(login_response)¶
Extract student data from login response.
- Parameters
login_response (Union[Response, dict]) – The response of the login request.
- Returns
Student data. Represented by
pymyku.attribute.Student- Return type
- Raises
ValueError – If student data is not found.
- pymyku.utils.extract_access_token(login_response)¶
Extract student code from login response
- Parameters
login_response (Union[Response, dict]) – This is the response from the login request.
- Returns
Access token. Represented by
pymyku.attribute.Token.ACCESS_TOKEN- Return type
- Raises
ValueError – If access token is not found.
- pymyku.utils.extract_std_code(login_response)¶
Extract student code from login response
- Parameters
login_response (Union[Response, dict]) – The response of the login request.
- Returns
Student code. Represented by
pymyku.attribute.Student.STD_CODE- Return type
- pymyku.utils.extract_std_id(login_response)¶
Extract student id from login response.
- Parameters
login_response (Union[Response, dict]) – The response of the login request.
- Returns
Student id. Represented by
pymyku.attribute.Student.STD_ID- Return type
- pymyku.utils.extract_schedule(schedule_response, as_dict=False, full_result=False)¶
Extract academic_year and semester from schedule response.
- Parameters
schedule_response (Union[Response, dict]) – The response from the schedule request.
as_dict (Optional[bool]) – Whether to return the result as a dictionary or not. By default False
full_result (Optional[bool]) – If True, return the full result (List[dict]), otherwise return the first item. By default False
- Returns
Academic year and semester. Represented by
pymyku.attribute.Schedule.ACADEMIC_YEARandpymyku.attribute.Schedule.SEMESTER- Return type
- pymyku.utils.gen_request_headers(access_token='')¶
Generate request headers.
Sets the access token as x-access-token if provided.
- Parameters
access_token (Optional[Union[str, Response, dict]]) – If the parameter is type Response or dict, the access token will be extracted. Represented by
pymyku.attribute.Token.ACCESS_TOKEN- Returns
Request headers for MyKU API.
- Return type
- pymyku.utils.gen_login_request_params(username, password)¶
Generate request parameters for posting login request.
- pymyku.utils.gen_request_args_f(function, raise_exception=True, **kwargs)¶
Generate request parameters requied for the given function.
Passing only login_response, schedule_response or client is also acceptable for some request parameters.
- Parameters
function (callable) – Any request function from pymyku.request module.
raise_exception (Optional[bool]) – Whether to raise exception or not, by default True
- Returns
Request parameters.
- Return type
Dict[str, any]
- Raises
ValueError – If required kwargs are not present.
Response attributes¶
- class pymyku.attribute.User(value)¶
Enum representation for user data in login response. Login response can be obtained by calling
pymyku.requests.login()or getting from client propertypymyku.Client.login_response- LOGIN_NAME = 'loginName'¶
A representation for loginName from user data in login response.
- USER_TYPE = 'userType'¶
A representation for userType from user data in login response.
- ID_CODE = 'idCode'¶
A representation for idCode from user data in login response.
- TITLE_TH = 'titleTh'¶
A representation for titleTh from user data in login response.
- TITLE_EN = 'titleEn'¶
A representation for titleEn from user data in login response.
- FIRST_NAME_TH = 'firstNameTh'¶
A representation for firstNameTh from user data in login response.
- FIRST_NAME_EN = 'firstNameEn'¶
A representation for firstNameEn from user data in login response.
- MIDDLE_NAME_TH = 'middleNameTh'¶
A representation for middleNameTh from user data in login response.
- MIDDLE_NAME_EN = 'middleNameEn'¶
A representation for middleNameEn from user data in login response.
- LAST_NAME_TH = 'lastNameTh'¶
A representation for lastNameTh from user data in login response.
- LAST_NAME_EN = 'lastNameEn'¶
A representation for lastNameEn from user data in login response.
- AVATAR = 'avatar'¶
A representation for avatar from user data in login response.
- GENDER = 'gender'¶
A representation for gender from user data in login response.
- class pymyku.attribute.Student(value)¶
Enum representation for student data in login response. Login response can be obtained by calling
pymyku.requests.login()or getting from client propertypymyku.Client.login_response- STD_ID = 'stdId'¶
A representation for stdId from student data in login response.
- STD_CODE = 'stdCode'¶
A representation for stdCode from student data in login response.
- COPEN_ID = 'copenId'¶
A representation for copenId from student data in login response.
- COPEN_NAME_TH = 'copenNameTh'¶
A representation for copenNameTh from student data in login response.
- COPEN_NAME_EN = 'copenNameEn'¶
A representation for copenNameEn from student data in login response.
- CAMPUS_CODE = 'campusCode'¶
A representation for campusCode from student data in login response.
- CAMPUS_NAME_TH = 'campusNameTh'¶
A representation for campusNameTh from student data in login response.
- CAMPUS_NAME_EN = 'campusNameEn'¶
A representation for campusNameEn from student data in login response.
- FACULTY_CODE = 'facultyCode'¶
A representation for facultyCode from student data in login response.
- FACULTY_NAME_TH = 'facultyNameTh'¶
A representation for facultyNameTh from student data in login response.
- FACULTY_NAME_EN = 'facultyNameEn'¶
A representation for facultyNameEn from student data in login response.
- DEPARTMENT_CODE = 'departmentCode'¶
A representation for departmentCode from student data in login response.
- DEPARTMENT_NAME_TH = 'departmentNameTh'¶
A representation for departmentNameTh from student data in login response.
- DEPARTMENT_NAME_EN = 'departmentNameEn'¶
A representation for departmentNameEn from student data in login response.
- MAJOR_CODE = 'majorCode'¶
A representation for majorCode from student data in login response.
- MAJOR_NAME_TH = 'majorNameTh'¶
A representation for majorNameTh from student data in login response.
- MAJOR_NAME_EN = 'majorNameEn'¶
A representation for majorNameEn from student data in login response.
- NATION_CODE = 'nationCode'¶
A representation for nationCode from student data in login response.
- NATIONALITY_NAME_TH = 'nationalityNameTh'¶
A representation for nationalityNameTh from student data in login response.
- NATIONALITY_NAME_EN = 'nationalityNameEn'¶
A representation for nationalityNameEn from student data in login response.
- STUDENT_STATUS_CODE = 'studentStatusCode'¶
A representation for studentStatusCode from student data in login response.
- STUDENT_STATUS_NAME_TH = 'studentStatusNameTh'¶
A representation for studentStatusNameTh from student data in login response.
- STUDENT_STATUS_NAME_EN = 'studentStatusNameEn'¶
A representation for studentStatusNameEn from student data in login response.
- STUDENT_TYPE_CODE = 'studentTypeCode'¶
A representation for studentTypeCode from student data in login response.
- STUDENT_TYPE_NAME_TH = 'studentTypeNameTh'¶
A representation for studentTypeNameTh from student data in login response.
- STUDENT_TYPE_NAME_EN = 'studentTypeNameEn'¶
A representation for studentTypeNameEn from student data in login response.
- EDULEVEL_CODE = 'edulevelCode'¶
A representation for edulevelCode from student data in login response.
- EDULEVEL_NAME_TH = 'edulevelNameTh'¶
A representation for edulevelNameTh from student data in login response.
- EDULEVEL_NAME_EN = 'edulevelNameEn'¶
A representation for edulevelNameEn from student data in login response.
- STUDENT_YEAR = 'studentYear'¶
A representation for studentYear from student data in login response.
- ADVISOR_ID = 'advisorId'¶
A representation for advisorId from student data in login response.
- ADVISOR_NAME_TH = 'advisorNameTh'¶
A representation for advisorNameTh from student data in login response.
- ADVISOR_NAME_EN = 'advisorNameEn'¶
A representation for advisorNameEn from student data in login response.
- POSITION_TH = 'positionTh'¶
A representation for positionTh from student data in login response.
- EMAIL = 'email'¶
A representation for email from student data in login response.
- MOBILE_NO = 'mobileNo'¶
A representation for mobileNo from student data in login response.
- class pymyku.attribute.Token(value)¶
Enum representation for tokens in login response. Login response can be obtained by calling
pymyku.requests.login()or getting from client propertypymyku.Client.login_response- ACCESS_TOKEN = 'accesstoken'¶
A representation for accessToken from login response.
- RENEW_TOKEN = 'renewtoken'¶
A representation for refreshToken from login response.
- class pymyku.attribute.Schedule(value)¶
Enum representation for schedule data in schedule response Schedule response can be obtained by calling
pymyku.requests.get_schedule()or getting from client propertypymyku.Client.schedule_response- ACADEMIC_YEAR = 'academicYr'¶
A representation for scheduleId from schedule response.
- SEMESTER = 'semester'¶
A representation for semester from schedule response.
- class pymyku.attribute.FetchedResponses(value)¶
Enum representation for fetched responses in client object
- LOGIN_RESPONSE = 0¶
A representation for login response in
pymyku.Client. Login response can be obtained by getting from client propertypymyku.Client.login_response
- SCHEDULE_RESPONSE = 1¶
A representation for schedule response in
pymyku.Client. Schedule response can be obtained by getting from client propertypymyku.Client.schedule_response
Types¶
- class pymyku.type.Enum(value)¶
Generic enumeration.
Derive from this class to define new enumerations.
- name¶
The name of the Enum member.
- value¶
The value of the Enum member.
- class pymyku.type.EnumMeta(cls, bases, classdict)¶
Metaclass for Enum
- class pymyku.type.Response¶
The
Responseobject, which contains a server’s response to an HTTP request.- status_code¶
Integer Code of responded HTTP Status, e.g. 404 or 200.
- headers¶
Case-insensitive Dictionary of Response Headers. For example,
headers['content-encoding']will return the value of a'Content-Encoding'response header.
- raw¶
File-like object representation of response (for advanced usage). Use of
rawrequires thatstream=Truebe set on the request. This requirement does not apply for use internally to Requests.
- url¶
Final URL location of Response.
- encoding¶
Encoding to decode with when accessing r.text.
- history¶
A list of
Responseobjects from the history of the Request. Any redirect responses will end up here. The list is sorted from the oldest to the most recent request.
- reason¶
Textual reason of responded HTTP Status, e.g. “Not Found” or “OK”.
- cookies¶
A CookieJar of Cookies the server sent back.
- elapsed¶
The amount of time elapsed between sending the request and the arrival of the response (as a timedelta). This property specifically measures the time taken between sending the first byte of the request and finishing parsing the headers. It is therefore unaffected by consuming the response content or the value of the
streamkeyword argument.
- request¶
The
PreparedRequestobject to which this is a response.
- property ok¶
Returns True if
status_codeis less than 400, False if not.This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code is between 200 and 400, this will return True. This is not a check to see if the response code is
200 OK.
- property is_redirect¶
True if this Response is a well-formed HTTP redirect that could have been processed automatically (by
Session.resolve_redirects()).
- property is_permanent_redirect¶
True if this Response one of the permanent versions of redirect.
- property next¶
Returns a PreparedRequest for the next request in a redirect chain, if there is one.
- property apparent_encoding¶
The apparent encoding, provided by the charset_normalizer or chardet libraries.
- iter_content(chunk_size=1, decode_unicode=False)¶
Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place.
chunk_size must be of type int or None. A value of None will function differently depending on the value of stream. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk.
If decode_unicode is True, content will be decoded using the best available encoding based on the response.
- for ... in iter_lines(chunk_size=512, decode_unicode=False, delimiter=None)¶
Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses.
Note
This method is not reentrant safe.
- property content¶
Content of the response, in bytes.
- property text¶
Content of the response, in unicode.
If Response.encoding is None, encoding will be guessed using
charset_normalizerorchardet.The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set
r.encodingappropriately before accessing this property.
- json(**kwargs)¶
Returns the json-encoded content of a response, if any.
- Parameters
**kwargs – Optional arguments that
json.loadstakes.- Raises
requests.exceptions.JSONDecodeError – If the response body does not contain valid json.
- property links¶
Returns the parsed header links of the response, if any.
- raise_for_status()¶
Raises
HTTPError, if one occurred.
- close()¶
Releases the connection back to the pool. Once this method has been called the underlying
rawobject must not be accessed again.Note: Should not normally need to be called explicitly.
- class pymyku.type.ClientType¶
Abstract class for client
URLs¶
See also: API Responses
- pymyku.url.LOGIN = 'https://myapi.ku.th/auth/login'¶
API for logging in to MyKU. API response – url.LOGIN
- pymyku.url.LOGOUT = 'https://myapi.ku.th/auth/logout'¶
API for logging out from MyKU (unsure if this works). API response – url.LOGOUT
- pymyku.url.SCHEDULE = 'https://myapi.ku.th/common/getschedule'¶
API for getting schedule data that contains academic year and semester. API response – url.SCHEDULE
- pymyku.url.ANNOUNCE = 'https://myapi.ku.th/advisor/getAnnounceStd'¶
API for getting announcement data. API response – url.ANNOUNCE
- pymyku.url.CHECK_GRADES = 'https://myapi.ku.th/std-profile/checkGrades'¶
API for getting grades for each semester. API response – url.CHECK_GRADES
- pymyku.url.GROUP_COURSE = 'https://myapi.ku.th/std-profile/getGroupCourse'¶
API for getting group course. API response – url.GROUP_COURSE
- pymyku.url.STUDENT_ADDRESS = 'https://myapi.ku.th/std-profile/getStdAddress'¶
API for getting student address information. API response – url.STUDENT_ADDRESS
- pymyku.url.STUDENT_PERSONAL = 'https://myapi.ku.th/std-profile/getStdPersonal'¶
API for getting student personal information. API response – url.STUDENT_PERSONAL
- pymyku.url.STUDENT_EDUCATION = 'https://myapi.ku.th/std-profile/getStdEducation'¶
API for getting student academic information. API response – url.STUDENT_EDUCATION
- pymyku.url.GPAX = 'https://myapi.ku.th/stddashboard/gpax'¶
API for getting gpx. API response – url.GPAX
- pymyku.url.SEARCH_ENROLL = 'https://myapi.ku.th/enroll/searchEnrollResult'¶
API for getting student enrollment data. API response – url.SEARCH_ENROLL
- pymyku.url.SEARCH_SUBJECT = 'https://myapi.ku.th/enroll/searchSubjectOpenEnr'¶
API for searching subject by subject code. API response – url.SEARCH_SUBJECT
- pymyku.url.SEARCH_SUBJECT_OPEN = 'https://myapi.ku.th/enroll/openSubjectForEnroll'¶
API for searching opening subject by subject code. API response – url.SEARCH_SUBJECT_OPEN
- pymyku.url.SEARCH_SECTION_DETAIL = 'https://myapi.ku.th/enroll/searchSectionDetail'¶
API for getting section detail by section id. API response – url.SEARCH_SECTION_DETAIL
Exceptions¶
- exception pymyku.exception.HTTPError(*args, **kwargs)¶
An HTTP error occurred.
- exception pymyku.exception.TokenExpired(*args, **kwargs)¶
The access token has expired.
Constants¶
- pymyku.constant.APP_KEY = 'txCR5732xYYWDGdd49M3R19o1OVwdRFc'¶
MyKU app key.
- pymyku.constant.STUDENT_PARAM_NAMES = ('std_id', 'std_code', 'campus_code', 'faculty_code', 'major_code', 'student_status_code', 'student_year')¶
Key in student data from login response (snake case).
- pymyku.constant.STUDENT_PARAM_RES_NAMES = ('stdId', 'stdCode', 'campusCode', 'facultyCode', 'majorCode', 'studentStatusCode', 'studentYear')¶
Key in student data from login response (actual).
- pymyku.constant.STUDENT_PARAM_DICT = {'campus_code': 'campusCode', 'faculty_code': 'facultyCode', 'major_code': 'majorCode', 'std_code': 'stdCode', 'std_id': 'stdId', 'student_status_code': 'studentStatusCode', 'student_year': 'studentYear'}¶
Dictionary to convert snake case student param to actual name.