iSJTU Interface =============== :class:`pysjtu.client.Client` is the main interface to the iSJTU API. It is composed of multiple mixins, each of which provides a set of methods to access a specific part of the API. Student ID ---------- .. autoattribute:: pysjtu.client.Client.student_id **Example:** To get the student id of current user: .. sourcecode:: python client.student_id # 519027910001 Term Start Date --------------- .. autoattribute:: pysjtu.client.Client.term_start_date **Example:** To get the start date of current term: .. sourcecode:: python client.term_start_date # datetime.date(2019, 9, 9) Schedule Query -------------- .. automodule:: pysjtu.client.api.schedule :members: **Example:** To fetch your schedule of the first term in 2019, filter by criteria, and dig into details: .. sourcecode:: python schedule = client.schedule(2019, 0) # [, ...] schedule.filter(time=[1, range(5, 7)], day=[2, range(4, 5)])) # [, # , # , # ] schedule[0].name # '军事理论' Exam Query ---------- .. automodule:: pysjtu.client.api.exam :members: **Example:** To get your exams of the first term in 2019, filter by criteria, and dig into details: .. sourcecode:: python exams = client.exam(2019, 0) # [, ...] exams.filter(date=datetime.date(2019, 12, 31)) # [] exams[0].name # '2019-2020-1数学期中考' Score Query ----------- .. automodule:: pysjtu.client.api.score :members: **Example:** To get your exams of the first term in 2019, filter by criteria, and dig into details: .. sourcecode:: python scores = client.score(2019, 0) # [, ...> scores.filter(gp=4) # [, ...] score = scores[0] # score.name # '大学化学' score_detail = score.detail # [, ] score_detail[0].percentage # 0.4 GPA Query --------- .. automodule:: pysjtu.client.api.gpa :members: **Example:** To fetch default GPA query parameters, change statistics scope and query GPA statistics: .. sourcecode:: python query = client.default_gpa_query_params # query.course_range = CourseRange.ALL gpa = client.gpa(query) # gpa.gpa # 4.3 College-Wide Course Search -------------------------- .. automodule:: pysjtu.client.api.course :members: **Example:** To perform a college-wide course search: .. sourcecode:: python courses = client.query_course(2019, 0, name="高等数学") # len(courses) # 90 courses[-1] # courses[14:16] # [, ] list(courses) # [, , ...] courses[0].credit # 4.0 Course Selection ---------------- .. automodule:: pysjtu.client.api.selection :members: **Example:** To select/drop a course: .. sourcecode:: python # First, get course sectors sectors = client.course_selection_sectors sector = next(filter(lambda x: x == "主修", sectors)) # Then, fetch class list classes = sector.classes klass = next(filter(lambda x: x.class_name == "CS2305", classes)) # Finally, select/drop the class while True: time.sleep(1) try: klass.register() # or klass.drop() break except FullCapacityException: pass # retry except Exception as e: raise e # or handle other exceptions