usos-api 0.3.0__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {usos_api-0.3.0 → usos_api-0.3.1}/PKG-INFO +6 -5
- {usos_api-0.3.0 → usos_api-0.3.1}/pyproject.toml +5 -5
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/helper.py +2 -11
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/course.py +14 -4
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/term.py +1 -1
- usos_api-0.3.1/usos_api/services/courses.py +84 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/grades.py +5 -1
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/groups.py +1 -1
- usos_api-0.3.0/usos_api/services/courses.py +0 -52
- {usos_api-0.3.0 → usos_api-0.3.1}/README.md +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/__init__.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/auth.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/client.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/connection.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/exceptions.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/logger.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/__init__.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/api_documentation.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/consumer.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/grade.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/group.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/lang_dict.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/programme.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/registration.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/models/user.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/__init__.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/api_documentation.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/api_server.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/registrations.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/terms.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/services/users.py +0 -0
- {usos_api-0.3.0 → usos_api-0.3.1}/usos_api/utils/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: usos-api
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Asynchronous USOS API for Python
|
|
5
5
|
Home-page: https://github.com/Antoni-Czaplicki/usos-api
|
|
6
6
|
Author: Antoni-Czaplicki
|
|
@@ -10,10 +10,11 @@ Classifier: Programming Language :: Python :: 3
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.10
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
|
|
14
|
-
Requires-Dist:
|
|
15
|
-
Requires-Dist:
|
|
16
|
-
Requires-Dist:
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: aiohttp (>=3.11,<4.0)
|
|
15
|
+
Requires-Dist: oauthlib (>=3.2,<4.0)
|
|
16
|
+
Requires-Dist: pydantic (>=2.10,<3.0)
|
|
17
|
+
Requires-Dist: python-dotenv (>=1.0,<2.0)
|
|
17
18
|
Project-URL: Documentation, https://usos-api.readthedocs.io
|
|
18
19
|
Project-URL: Repository, https://github.com/Antoni-Czaplicki/usos-api
|
|
19
20
|
Description-Content-Type: text/markdown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "usos-api"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.1"
|
|
4
4
|
description = "Asynchronous USOS API for Python"
|
|
5
5
|
authors = ["Antoni-Czaplicki <56671347+Antoni-Czaplicki@users.noreply.github.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -10,10 +10,10 @@ documentation = "https://usos-api.readthedocs.io"
|
|
|
10
10
|
|
|
11
11
|
[tool.poetry.dependencies]
|
|
12
12
|
python = "^3.10"
|
|
13
|
-
aiohttp = "^3.
|
|
14
|
-
pydantic = "^2.
|
|
15
|
-
oauthlib = "^3.2
|
|
16
|
-
python-dotenv = "^1.0
|
|
13
|
+
aiohttp = "^3.11"
|
|
14
|
+
pydantic = "^2.10"
|
|
15
|
+
oauthlib = "^3.2"
|
|
16
|
+
python-dotenv = "^1.0"
|
|
17
17
|
|
|
18
18
|
[tool.poetry.group.dev.dependencies]
|
|
19
19
|
black = "*"
|
|
@@ -22,18 +22,9 @@ class APIHelper:
|
|
|
22
22
|
ects_by_term = await self.client.course_service.get_user_courses_ects()
|
|
23
23
|
terms = await self.client.term_service.get_terms(list(ects_by_term.keys()))
|
|
24
24
|
term_ids = [
|
|
25
|
-
term.id for term in terms if not current_term_only or term.
|
|
26
|
-
]
|
|
27
|
-
course_ids = [
|
|
28
|
-
course_id
|
|
29
|
-
for term_id in term_ids
|
|
30
|
-
for course_id in ects_by_term[term_id].keys()
|
|
25
|
+
term.id for term in terms if not current_term_only or term.is_ongoing
|
|
31
26
|
]
|
|
32
27
|
|
|
33
|
-
courses = {
|
|
34
|
-
course.id: course
|
|
35
|
-
for course in await self.client.course_service.get_courses(course_ids)
|
|
36
|
-
}
|
|
37
28
|
grades_by_term = await self.client.grade_service.get_grades_by_terms(term_ids)
|
|
38
29
|
|
|
39
30
|
user_grades = []
|
|
@@ -47,7 +38,7 @@ class APIHelper:
|
|
|
47
38
|
for grade in grades:
|
|
48
39
|
grade.weight = ects
|
|
49
40
|
grade.course_edition = CourseEdition(
|
|
50
|
-
|
|
41
|
+
course_id=course_id, term_id=term.id
|
|
51
42
|
)
|
|
52
43
|
user_grades.append(grade)
|
|
53
44
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Optional
|
|
1
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
@@ -65,13 +65,23 @@ class CourseEdition(BaseModel):
|
|
|
65
65
|
Class representing a course edition.
|
|
66
66
|
"""
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
course_id: str | None = None
|
|
69
|
+
course_name: LangDict | None = None
|
|
70
|
+
term_id: str | None = None
|
|
70
71
|
homepage_url: str | None = None
|
|
72
|
+
profile_url: str | None = None
|
|
73
|
+
coordinators: list[dict[str, Any]] | None = None
|
|
74
|
+
lecturers: list[dict[str, Any]] | None = None
|
|
75
|
+
passing_status: str | None = None # passed, failed, not_yet_passed
|
|
76
|
+
user_groups: list[Group] | None = None
|
|
77
|
+
|
|
71
78
|
description: LangDict | None = None
|
|
72
79
|
bibliography: LangDict | None = None
|
|
73
80
|
notes: LangDict | None = None
|
|
74
|
-
|
|
81
|
+
course_units_ids: list[str] | None = None
|
|
82
|
+
participants: list[dict[str, Any]] | None = None
|
|
83
|
+
grades: list[dict[str, Any]] | None = None
|
|
84
|
+
attributes: list[dict[str, list[LangDict]]] | None = None
|
|
75
85
|
|
|
76
86
|
|
|
77
87
|
class CourseEditionConducted(BaseModel):
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from ..connection import USOSAPIConnection
|
|
4
|
+
from ..models import Course, CourseEdition, Term
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CourseService:
|
|
8
|
+
"""
|
|
9
|
+
A service for course-related operations.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, connection: USOSAPIConnection):
|
|
13
|
+
"""
|
|
14
|
+
Initialize the course service.
|
|
15
|
+
|
|
16
|
+
:param connection: The connection to use.
|
|
17
|
+
"""
|
|
18
|
+
self.connection = connection
|
|
19
|
+
|
|
20
|
+
async def get_user_courses_ects(self) -> dict[str, dict[str, float]]:
|
|
21
|
+
"""
|
|
22
|
+
Get user courses ECTS.
|
|
23
|
+
|
|
24
|
+
:return: The user courses ECTS.
|
|
25
|
+
"""
|
|
26
|
+
response = await self.connection.post("services/courses/user_ects_points")
|
|
27
|
+
return {
|
|
28
|
+
term: {course: float(points) for course, points in courses.items()}
|
|
29
|
+
for term, courses in response.items()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async def get_courses(
|
|
33
|
+
self, course_ids: list[str], fields: Optional[list[str]] = None
|
|
34
|
+
) -> list[Course]:
|
|
35
|
+
"""
|
|
36
|
+
Get courses by their IDs.
|
|
37
|
+
|
|
38
|
+
:param course_ids: The IDs of the courses to get.
|
|
39
|
+
:param fields: The fields to include in the response.
|
|
40
|
+
:return: A list of courses.
|
|
41
|
+
"""
|
|
42
|
+
if not course_ids:
|
|
43
|
+
return []
|
|
44
|
+
|
|
45
|
+
course_ids_str = "|".join(course_ids)
|
|
46
|
+
fields_str = "|".join(fields) if fields else "id|name"
|
|
47
|
+
|
|
48
|
+
response = await self.connection.post(
|
|
49
|
+
"services/courses/courses", course_ids=course_ids_str, fields=fields_str
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
return [Course(**course_data) for course_data in response.values()]
|
|
53
|
+
|
|
54
|
+
async def get_user_course_editions(
|
|
55
|
+
self,
|
|
56
|
+
active_terms_only: bool = False,
|
|
57
|
+
ongoing_terms_only: bool = False,
|
|
58
|
+
) -> list[CourseEdition]:
|
|
59
|
+
"""
|
|
60
|
+
Get information on user's courses.
|
|
61
|
+
|
|
62
|
+
This is a BETA method. We're looking for beta-testers. Until we find them, there's a substantial probability it won't stay backwards-compatible!
|
|
63
|
+
If you are planning on using this method, please let us know. Then, we will work with you and move it out of beta as soon as we can.
|
|
64
|
+
|
|
65
|
+
:param active_terms_only: Return only these course editions which are related to the currently active academic terms. Apparently, this parameter does not always work as expected, so you can use `ongoing_terms_only` instead.
|
|
66
|
+
:param ongoing_terms_only: Return only these course editions which are related to the currently ongoing academic terms (filtered locally based on start and finish dates).
|
|
67
|
+
:return: A dictionary of selected fields and their values.
|
|
68
|
+
"""
|
|
69
|
+
params = {
|
|
70
|
+
"fields": "course_editions[course_id|course_name|term_id|homepage_url|profile_url|coordinators|lecturers|passing_status|user_groups|grades|attributes]|terms",
|
|
71
|
+
"active_terms_only": str(active_terms_only).lower(),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
response = await self.connection.post("services/courses/user", **params)
|
|
75
|
+
|
|
76
|
+
terms = {term["id"]: Term(**term) for term in response["terms"]}
|
|
77
|
+
ongoing_terms = {term_id for term_id, term in terms.items() if term.is_ongoing}
|
|
78
|
+
|
|
79
|
+
return [
|
|
80
|
+
CourseEdition(**course_edition)
|
|
81
|
+
for term_id, course_editions in response["course_editions"].items()
|
|
82
|
+
if not ongoing_terms_only or term_id in ongoing_terms
|
|
83
|
+
for course_edition in course_editions
|
|
84
|
+
]
|
|
@@ -84,6 +84,7 @@ class GradeService:
|
|
|
84
84
|
exam_session_number: Grade(**grade)
|
|
85
85
|
for unit in units
|
|
86
86
|
for exam_session_number, grade in unit.items()
|
|
87
|
+
if grade
|
|
87
88
|
}
|
|
88
89
|
return processed_units_grades
|
|
89
90
|
|
|
@@ -95,5 +96,8 @@ class GradeService:
|
|
|
95
96
|
:return: The processed course grades.
|
|
96
97
|
"""
|
|
97
98
|
return [
|
|
98
|
-
Grade(**grade)
|
|
99
|
+
Grade(**grade)
|
|
100
|
+
for session in course_grades
|
|
101
|
+
for grade in session.values()
|
|
102
|
+
if grade
|
|
99
103
|
]
|
|
@@ -10,7 +10,7 @@ def _filter_ongoing_terms(terms: list[Term]) -> list[Term]:
|
|
|
10
10
|
:param terms: The terms to filter.
|
|
11
11
|
:return: The ongoing terms.
|
|
12
12
|
"""
|
|
13
|
-
return [term for term in terms if term.
|
|
13
|
+
return [term for term in terms if term.is_ongoing]
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def _deserialize_term(data: dict) -> Term:
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
from ..connection import USOSAPIConnection
|
|
4
|
-
from ..models import Course
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class CourseService:
|
|
8
|
-
"""
|
|
9
|
-
A service for course-related operations.
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
def __init__(self, connection: USOSAPIConnection):
|
|
13
|
-
"""
|
|
14
|
-
Initialize the course service.
|
|
15
|
-
|
|
16
|
-
:param connection: The connection to use.
|
|
17
|
-
"""
|
|
18
|
-
self.connection = connection
|
|
19
|
-
|
|
20
|
-
async def get_user_courses_ects(self) -> dict[str, dict[str, float]]:
|
|
21
|
-
"""
|
|
22
|
-
Get user courses ECTS.
|
|
23
|
-
|
|
24
|
-
:return: The user courses ECTS.
|
|
25
|
-
"""
|
|
26
|
-
response = await self.connection.post("services/courses/user_ects_points")
|
|
27
|
-
return {
|
|
28
|
-
term: {course: float(points) for course, points in courses.items()}
|
|
29
|
-
for term, courses in response.items()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async def get_courses(
|
|
33
|
-
self, course_ids: list[str], fields: Optional[list[str]] = None
|
|
34
|
-
) -> list[Course]:
|
|
35
|
-
"""
|
|
36
|
-
Get courses by their IDs.
|
|
37
|
-
|
|
38
|
-
:param course_ids: The IDs of the courses to get.
|
|
39
|
-
:param fields: The fields to include in the response.
|
|
40
|
-
:return: A list of courses.
|
|
41
|
-
"""
|
|
42
|
-
if not course_ids:
|
|
43
|
-
return []
|
|
44
|
-
|
|
45
|
-
course_ids_str = "|".join(course_ids)
|
|
46
|
-
fields_str = "|".join(fields) if fields else "id|name"
|
|
47
|
-
|
|
48
|
-
response = await self.connection.post(
|
|
49
|
-
"services/courses/courses", course_ids=course_ids_str, fields=fields_str
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
return [Course(**course_data) for course_data in response.values()]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|