usos-api 0.3.3__tar.gz → 0.4.0__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.4.0/.github/workflows/publish.yml +33 -0
- usos_api-0.4.0/.gitignore +172 -0
- usos_api-0.4.0/.readthedocs.yaml +16 -0
- usos_api-0.4.0/PKG-INFO +20 -0
- usos_api-0.4.0/docs/Makefile +20 -0
- usos_api-0.4.0/docs/conf.py +45 -0
- usos_api-0.4.0/docs/full-docs.rst +47 -0
- usos_api-0.4.0/docs/index.rst +31 -0
- usos_api-0.4.0/docs/make.bat +35 -0
- usos_api-0.4.0/docs/quickstart.rst +96 -0
- usos_api-0.4.0/pyproject.toml +37 -0
- usos_api-0.4.0/run.py +105 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/auth.py +2 -4
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/client.py +3 -0
- usos_api-0.4.0/usos_api/helper.py +84 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/__init__.py +2 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/courses.py +27 -3
- usos_api-0.4.0/usos_api/services/exam_reports.py +599 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/groups.py +31 -2
- usos_api-0.4.0/uv.lock +1678 -0
- usos_api-0.3.3/PKG-INFO +0 -26
- usos_api-0.3.3/pyproject.toml +0 -34
- usos_api-0.3.3/usos_api/helper.py +0 -45
- {usos_api-0.3.3 → usos_api-0.4.0}/README.md +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/__init__.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/connection.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/exceptions.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/logger.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/__init__.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/api_documentation.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/consumer.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/course.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/grade.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/group.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/lang_dict.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/programme.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/registration.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/term.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/models/user.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/api_documentation.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/api_server.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/grades.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/registrations.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/terms.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/services/users.py +0 -0
- {usos_api-0.3.3 → usos_api-0.4.0}/usos_api/utils/__init__.py +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Publish Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout code
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v5
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: '3.12'
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
uv sync
|
|
27
|
+
|
|
28
|
+
- name: Build and publish package
|
|
29
|
+
env:
|
|
30
|
+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
|
31
|
+
run: |
|
|
32
|
+
uv build
|
|
33
|
+
uv publish
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
### Example user template template
|
|
2
|
+
### Example user template
|
|
3
|
+
|
|
4
|
+
# IntelliJ project files
|
|
5
|
+
.idea
|
|
6
|
+
*.iml
|
|
7
|
+
out
|
|
8
|
+
gen
|
|
9
|
+
### Python template
|
|
10
|
+
# Byte-compiled / optimized / DLL files
|
|
11
|
+
__pycache__/
|
|
12
|
+
*.py[cod]
|
|
13
|
+
*$py.class
|
|
14
|
+
|
|
15
|
+
# C extensions
|
|
16
|
+
*.so
|
|
17
|
+
|
|
18
|
+
# Distribution / packaging
|
|
19
|
+
.Python
|
|
20
|
+
build/
|
|
21
|
+
develop-eggs/
|
|
22
|
+
dist/
|
|
23
|
+
downloads/
|
|
24
|
+
eggs/
|
|
25
|
+
.eggs/
|
|
26
|
+
lib/
|
|
27
|
+
lib64/
|
|
28
|
+
parts/
|
|
29
|
+
sdist/
|
|
30
|
+
var/
|
|
31
|
+
wheels/
|
|
32
|
+
share/python-wheels/
|
|
33
|
+
*.egg-info/
|
|
34
|
+
.installed.cfg
|
|
35
|
+
*.egg
|
|
36
|
+
MANIFEST
|
|
37
|
+
|
|
38
|
+
# PyInstaller
|
|
39
|
+
# Usually these files are written by a python script from a template
|
|
40
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
41
|
+
*.manifest
|
|
42
|
+
*.spec
|
|
43
|
+
|
|
44
|
+
# Installer logs
|
|
45
|
+
pip-log.txt
|
|
46
|
+
pip-delete-this-directory.txt
|
|
47
|
+
|
|
48
|
+
# Unit test / coverage reports
|
|
49
|
+
htmlcov/
|
|
50
|
+
.tox/
|
|
51
|
+
.nox/
|
|
52
|
+
.coverage
|
|
53
|
+
.coverage.*
|
|
54
|
+
.cache
|
|
55
|
+
nosetests.xml
|
|
56
|
+
coverage.xml
|
|
57
|
+
*.cover
|
|
58
|
+
*.py,cover
|
|
59
|
+
.hypothesis/
|
|
60
|
+
.pytest_cache/
|
|
61
|
+
cover/
|
|
62
|
+
|
|
63
|
+
# Translations
|
|
64
|
+
*.mo
|
|
65
|
+
*.pot
|
|
66
|
+
|
|
67
|
+
# Django stuff:
|
|
68
|
+
*.log
|
|
69
|
+
local_settings.py
|
|
70
|
+
db.sqlite3
|
|
71
|
+
db.sqlite3-journal
|
|
72
|
+
|
|
73
|
+
# Flask stuff:
|
|
74
|
+
instance/
|
|
75
|
+
.webassets-cache
|
|
76
|
+
|
|
77
|
+
# Scrapy stuff:
|
|
78
|
+
.scrapy
|
|
79
|
+
|
|
80
|
+
# Sphinx documentation
|
|
81
|
+
docs/_build/
|
|
82
|
+
|
|
83
|
+
# PyBuilder
|
|
84
|
+
.pybuilder/
|
|
85
|
+
target/
|
|
86
|
+
|
|
87
|
+
# Jupyter Notebook
|
|
88
|
+
.ipynb_checkpoints
|
|
89
|
+
|
|
90
|
+
# IPython
|
|
91
|
+
profile_default/
|
|
92
|
+
ipython_config.py
|
|
93
|
+
|
|
94
|
+
# pyenv
|
|
95
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
96
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
97
|
+
# .python-version
|
|
98
|
+
|
|
99
|
+
# pipenv
|
|
100
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
101
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
102
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
103
|
+
# install all needed dependencies.
|
|
104
|
+
#Pipfile.lock
|
|
105
|
+
|
|
106
|
+
# poetry
|
|
107
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
108
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
109
|
+
# commonly ignored for libraries.
|
|
110
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
111
|
+
#poetry.lock
|
|
112
|
+
|
|
113
|
+
# pdm
|
|
114
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
115
|
+
#pdm.lock
|
|
116
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
117
|
+
# in version control.
|
|
118
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
119
|
+
.pdm.toml
|
|
120
|
+
|
|
121
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
122
|
+
__pypackages__/
|
|
123
|
+
|
|
124
|
+
# Celery stuff
|
|
125
|
+
celerybeat-schedule
|
|
126
|
+
celerybeat.pid
|
|
127
|
+
|
|
128
|
+
# SageMath parsed files
|
|
129
|
+
*.sage.py
|
|
130
|
+
|
|
131
|
+
# Environments
|
|
132
|
+
.env
|
|
133
|
+
.venv
|
|
134
|
+
env/
|
|
135
|
+
venv/
|
|
136
|
+
ENV/
|
|
137
|
+
env.bak/
|
|
138
|
+
venv.bak/
|
|
139
|
+
|
|
140
|
+
# Spyder project settings
|
|
141
|
+
.spyderproject
|
|
142
|
+
.spyproject
|
|
143
|
+
|
|
144
|
+
# Rope project settings
|
|
145
|
+
.ropeproject
|
|
146
|
+
|
|
147
|
+
# mkdocs documentation
|
|
148
|
+
/site
|
|
149
|
+
|
|
150
|
+
# mypy
|
|
151
|
+
.mypy_cache/
|
|
152
|
+
.dmypy.json
|
|
153
|
+
dmypy.json
|
|
154
|
+
|
|
155
|
+
# Pyre type checker
|
|
156
|
+
.pyre/
|
|
157
|
+
|
|
158
|
+
# pytype static type analyzer
|
|
159
|
+
.pytype/
|
|
160
|
+
|
|
161
|
+
# Cython debug symbols
|
|
162
|
+
cython_debug/
|
|
163
|
+
|
|
164
|
+
# PyCharm
|
|
165
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
166
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
167
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
168
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
169
|
+
#.idea/
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
usos_api_access_token.json
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
|
|
3
|
+
build:
|
|
4
|
+
os: "ubuntu-22.04"
|
|
5
|
+
tools:
|
|
6
|
+
python: "3.12"
|
|
7
|
+
jobs:
|
|
8
|
+
post_create_environment:
|
|
9
|
+
# Install uv
|
|
10
|
+
- pip install uv
|
|
11
|
+
post_install:
|
|
12
|
+
# Install dependencies with 'docs' dependency group
|
|
13
|
+
- uv export --format requirements.txt --group docs | uv pip install --python $READTHEDOCS_VIRTUALENV_PATH -r /dev/stdin
|
|
14
|
+
|
|
15
|
+
sphinx:
|
|
16
|
+
configuration: docs/conf.py
|
usos_api-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: usos-api
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Asynchronous USOS API for Python
|
|
5
|
+
Project-URL: Homepage, https://github.com/Antoni-Czaplicki/usos-api
|
|
6
|
+
Project-URL: Repository, https://github.com/Antoni-Czaplicki/usos-api
|
|
7
|
+
Project-URL: Documentation, https://usos-api.readthedocs.io
|
|
8
|
+
Author-email: Antoni-Czaplicki <56671347+Antoni-Czaplicki@users.noreply.github.com>
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: aiohttp==3.13.3
|
|
11
|
+
Requires-Dist: oauthlib>=3.3
|
|
12
|
+
Requires-Dist: pydantic>=2.12
|
|
13
|
+
Requires-Dist: python-dotenv>=1.2
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# USOS API for python, in development
|
|
17
|
+
|
|
18
|
+
This is a python library for USOS API. It is in development, so it is not recommended to use it in production.
|
|
19
|
+
|
|
20
|
+
Visit [documentation](https://usos-api.readthedocs.io) for more information.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line, and also
|
|
5
|
+
# from the environment for the first two.
|
|
6
|
+
SPHINXOPTS ?=
|
|
7
|
+
SPHINXBUILD ?= sphinx-build
|
|
8
|
+
SOURCEDIR = .
|
|
9
|
+
BUILDDIR = _build
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
4
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
5
|
+
|
|
6
|
+
import datetime
|
|
7
|
+
|
|
8
|
+
# -- Project information -----------------------------------------------------
|
|
9
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from importlib.metadata import version as get_version
|
|
13
|
+
|
|
14
|
+
sys.path.insert(0, os.path.abspath(".."))
|
|
15
|
+
|
|
16
|
+
project = "USOS API"
|
|
17
|
+
|
|
18
|
+
author = "Antoni Czaplicki"
|
|
19
|
+
release = get_version("usos-api")
|
|
20
|
+
version = release
|
|
21
|
+
|
|
22
|
+
current_year = datetime.datetime.now().year
|
|
23
|
+
copyright = f"{current_year}, {author}"
|
|
24
|
+
|
|
25
|
+
# -- General configuration ---------------------------------------------------
|
|
26
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
extensions = [
|
|
30
|
+
"sphinx.ext.autodoc",
|
|
31
|
+
"sphinx.ext.autosummary",
|
|
32
|
+
"sphinx.ext.viewcode",
|
|
33
|
+
"sphinx_autodoc_typehints",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
templates_path = ["_templates"]
|
|
37
|
+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
|
38
|
+
|
|
39
|
+
# -- Options for HTML output -------------------------------------------------
|
|
40
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
41
|
+
|
|
42
|
+
html_theme = "sphinx_rtd_theme"
|
|
43
|
+
html_static_path = ["_static"]
|
|
44
|
+
|
|
45
|
+
master_doc = "index"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Full API documentation
|
|
2
|
+
===========================
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
.. toctree::
|
|
6
|
+
|
|
7
|
+
Client
|
|
8
|
+
^^^^^^
|
|
9
|
+
|
|
10
|
+
.. autoclass:: usos_api.client.USOSClient
|
|
11
|
+
:members:
|
|
12
|
+
:show-inheritance:
|
|
13
|
+
|
|
14
|
+
Connection
|
|
15
|
+
^^^^^^^^^^
|
|
16
|
+
|
|
17
|
+
.. autoclass:: usos_api.connection.USOSAPIConnection
|
|
18
|
+
:members:
|
|
19
|
+
:show-inheritance:
|
|
20
|
+
|
|
21
|
+
Auth
|
|
22
|
+
^^^^
|
|
23
|
+
|
|
24
|
+
.. autoclass:: usos_api.auth.AuthManager
|
|
25
|
+
:members:
|
|
26
|
+
:show-inheritance:
|
|
27
|
+
|
|
28
|
+
logger
|
|
29
|
+
^^^^^^
|
|
30
|
+
|
|
31
|
+
.. automodule:: usos_api.logger
|
|
32
|
+
:members:
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Services
|
|
36
|
+
^^^^^^^^
|
|
37
|
+
|
|
38
|
+
.. automodule:: usos_api.services
|
|
39
|
+
:members:
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Helper
|
|
43
|
+
^^^^^^
|
|
44
|
+
|
|
45
|
+
.. autoclass:: usos_api.helper.APIHelper
|
|
46
|
+
:members:
|
|
47
|
+
:show-inheritance:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.. USOS API documentation master file, created by
|
|
2
|
+
sphinx-quickstart on Sat Jul 6 11:21:09 2024.
|
|
3
|
+
You can adapt this file completely to your liking, but it should at least
|
|
4
|
+
contain the root `toctree` directive.
|
|
5
|
+
|
|
6
|
+
Welcome to USOS API's documentation!
|
|
7
|
+
====================================
|
|
8
|
+
|
|
9
|
+
Setup Instructions
|
|
10
|
+
------------------
|
|
11
|
+
|
|
12
|
+
1. Install package:
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
pip install usos-api
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
.. toctree::
|
|
19
|
+
:maxdepth: 2
|
|
20
|
+
:caption: Main Sections:
|
|
21
|
+
|
|
22
|
+
quickstart
|
|
23
|
+
full-docs
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Indices and tables
|
|
27
|
+
==================
|
|
28
|
+
|
|
29
|
+
* :ref:`genindex`
|
|
30
|
+
* :ref:`modindex`
|
|
31
|
+
* :ref:`search`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@ECHO OFF
|
|
2
|
+
|
|
3
|
+
pushd %~dp0
|
|
4
|
+
|
|
5
|
+
REM Command file for Sphinx documentation
|
|
6
|
+
|
|
7
|
+
if "%SPHINXBUILD%" == "" (
|
|
8
|
+
set SPHINXBUILD=sphinx-build
|
|
9
|
+
)
|
|
10
|
+
set SOURCEDIR=.
|
|
11
|
+
set BUILDDIR=_build
|
|
12
|
+
|
|
13
|
+
%SPHINXBUILD% >NUL 2>NUL
|
|
14
|
+
if errorlevel 9009 (
|
|
15
|
+
echo.
|
|
16
|
+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
|
17
|
+
echo.installed, then set the SPHINXBUILD environment variable to point
|
|
18
|
+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
|
19
|
+
echo.may add the Sphinx directory to PATH.
|
|
20
|
+
echo.
|
|
21
|
+
echo.If you don't have Sphinx installed, grab it from
|
|
22
|
+
echo.https://www.sphinx-doc.org/
|
|
23
|
+
exit /b 1
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
if "%1" == "" goto help
|
|
27
|
+
|
|
28
|
+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
|
29
|
+
goto end
|
|
30
|
+
|
|
31
|
+
:help
|
|
32
|
+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
|
33
|
+
|
|
34
|
+
:end
|
|
35
|
+
popd
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Getting Started with USOS API
|
|
2
|
+
=============================
|
|
3
|
+
|
|
4
|
+
This page will guide you through the installation and basic usage of the USOS API package.
|
|
5
|
+
|
|
6
|
+
Installation
|
|
7
|
+
------------
|
|
8
|
+
|
|
9
|
+
The USOS API package can be installed using pip:
|
|
10
|
+
|
|
11
|
+
.. code-block:: bash
|
|
12
|
+
|
|
13
|
+
pip install usos-api
|
|
14
|
+
|
|
15
|
+
Setting Up
|
|
16
|
+
----------
|
|
17
|
+
|
|
18
|
+
Before you can use the USOS API, you need to set up your API keys. These can be obtained from the USOS API website.
|
|
19
|
+
Remember that you need separate keys for each of the USOS serservers you want to access. You can find the list of available servers `here <https://apps.usos.edu.pl/developers/api/definitions/installations/>`_.
|
|
20
|
+
|
|
21
|
+
Preferred way of storing your API keys is to use environment variables. You can use the ``python-dotenv`` package to load them from a `.env` file. Here's an example of how to do it:
|
|
22
|
+
|
|
23
|
+
.. code-block:: python
|
|
24
|
+
|
|
25
|
+
import os
|
|
26
|
+
from dotenv import load_dotenv
|
|
27
|
+
|
|
28
|
+
load_dotenv()
|
|
29
|
+
|
|
30
|
+
api_base_address = os.environ.get("USOS_API_BASE_ADDRESS")
|
|
31
|
+
consumer_key = os.environ.get("USOS_CONSUMER_KEY")
|
|
32
|
+
consumer_secret = os.environ.get("USOS_CONSUMER_SECRET")
|
|
33
|
+
|
|
34
|
+
Technical info
|
|
35
|
+
--------------
|
|
36
|
+
|
|
37
|
+
The USOS API is asynchronous (using ``asyncio``) and works using
|
|
38
|
+
coroutines. All the code presented in this documentation needs to be placed
|
|
39
|
+
inside a coroutine block (except imports, obviously).
|
|
40
|
+
|
|
41
|
+
A sample coroutine block looks as follows:
|
|
42
|
+
|
|
43
|
+
.. code-block:: python
|
|
44
|
+
|
|
45
|
+
import asyncio
|
|
46
|
+
|
|
47
|
+
async def main():
|
|
48
|
+
# asynchronous code goes here
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
asyncio.run(main())
|
|
52
|
+
|
|
53
|
+
Authentication
|
|
54
|
+
--------------
|
|
55
|
+
|
|
56
|
+
The USOS API uses OAuth 1.0a for authentication. The ``USOSClient`` class provides a method to authenticate with the USOS API. Here's an example of how to do it:
|
|
57
|
+
|
|
58
|
+
.. code-block:: python
|
|
59
|
+
|
|
60
|
+
from usos_api.client import USOSClient
|
|
61
|
+
|
|
62
|
+
async with USOSClient(api_base_address, consumer_key, consumer_secret) as client:
|
|
63
|
+
print(await client.get_authorization_url()) # Open this URL in your browser, by default no callback URL is needed and you can just copy the PIN from the page you are redirected to
|
|
64
|
+
verifier = input("Enter the PIN: ")
|
|
65
|
+
await client.authorize(verifier)
|
|
66
|
+
|
|
67
|
+
Basic Usage
|
|
68
|
+
-----------
|
|
69
|
+
|
|
70
|
+
Here's a basic example of how to use the USOS API to fetch user data:
|
|
71
|
+
|
|
72
|
+
.. code-block:: python
|
|
73
|
+
|
|
74
|
+
from usos_api.client import USOSClient
|
|
75
|
+
|
|
76
|
+
async with USOSClient(api_base_address, consumer_key, consumer_secret) as client:
|
|
77
|
+
load_access_token("access_token", "access_token_secret")
|
|
78
|
+
user = await client.user_service.get_user()
|
|
79
|
+
print(user)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
You can also use the USOSClient without the context manager, but remember to close the client after you are done:
|
|
83
|
+
|
|
84
|
+
.. code-block:: python
|
|
85
|
+
|
|
86
|
+
from usos_api.client import USOSClient
|
|
87
|
+
|
|
88
|
+
client = USOSClient(api_base_address, consumer_key, consumer_secret)
|
|
89
|
+
await client.open()
|
|
90
|
+
load_access_token("access_token", "access_token_secret")
|
|
91
|
+
user = await client.user_service.get_user()
|
|
92
|
+
print(user)
|
|
93
|
+
await client.close()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
For more detailed usage, please refer to the full documentation.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "usos-api"
|
|
3
|
+
version = "0.4.0"
|
|
4
|
+
description = "Asynchronous USOS API for Python"
|
|
5
|
+
authors = [
|
|
6
|
+
{ name = "Antoni-Czaplicki", email = "56671347+Antoni-Czaplicki@users.noreply.github.com" }
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"aiohttp==3.13.3",
|
|
12
|
+
"oauthlib>=3.3",
|
|
13
|
+
"pydantic>=2.12",
|
|
14
|
+
"python-dotenv>=1.2"
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com/Antoni-Czaplicki/usos-api"
|
|
19
|
+
Repository = "https://github.com/Antoni-Czaplicki/usos-api"
|
|
20
|
+
Documentation = "https://usos-api.readthedocs.io"
|
|
21
|
+
|
|
22
|
+
[dependency-groups]
|
|
23
|
+
dev = [
|
|
24
|
+
"black",
|
|
25
|
+
"isort",
|
|
26
|
+
"ruff"
|
|
27
|
+
]
|
|
28
|
+
docs = [
|
|
29
|
+
"readthedocs-sphinx-search",
|
|
30
|
+
"sphinx",
|
|
31
|
+
"sphinx-autodoc-typehints",
|
|
32
|
+
"sphinx-rtd-theme"
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling"]
|
|
37
|
+
build-backend = "hatchling.build"
|
usos_api-0.4.0/run.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
""" Example of fetching user data from the USOS API. """
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from dotenv import load_dotenv
|
|
8
|
+
|
|
9
|
+
from usos_api.client import USOSClient
|
|
10
|
+
from usos_api.exceptions import USOSAPIException
|
|
11
|
+
|
|
12
|
+
load_dotenv()
|
|
13
|
+
|
|
14
|
+
DEFAULT_API_BASE_ADDRESS = "https://apps.usos.pwr.edu.pl/"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
async def fetch_data(api_base_address: str, consumer_key: str, consumer_secret: str):
|
|
18
|
+
try:
|
|
19
|
+
async with USOSClient(
|
|
20
|
+
api_base_address, consumer_key, consumer_secret
|
|
21
|
+
) as client:
|
|
22
|
+
try:
|
|
23
|
+
await client.load_access_token_from_file()
|
|
24
|
+
await client.api_server_service.get_consumer_info() # Check if the token is valid
|
|
25
|
+
except: # noqa
|
|
26
|
+
print("No token found")
|
|
27
|
+
print("Please visit the following URL to authorize the client:")
|
|
28
|
+
client.set_scopes(["studies", "photo"])
|
|
29
|
+
print(await client.get_authorization_url())
|
|
30
|
+
verifier = input("Enter the PIN: ")
|
|
31
|
+
await client.authorize(verifier)
|
|
32
|
+
await client.save_access_token_to_file()
|
|
33
|
+
|
|
34
|
+
user = await client.user_service.get_user()
|
|
35
|
+
if user:
|
|
36
|
+
print(user)
|
|
37
|
+
else:
|
|
38
|
+
print("User not found")
|
|
39
|
+
|
|
40
|
+
groups = await client.group_service.get_groups_for_participant(
|
|
41
|
+
ongoing_terms_only=True
|
|
42
|
+
)
|
|
43
|
+
print(groups)
|
|
44
|
+
print(await client.helper.get_user_end_grades_with_weights())
|
|
45
|
+
except USOSAPIException as e:
|
|
46
|
+
print(f"Error fetching data: {e}")
|
|
47
|
+
finally:
|
|
48
|
+
if client:
|
|
49
|
+
await client.close()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def fetch_documentation(
|
|
53
|
+
api_base_address: str, consumer_key: str, consumer_secret: str
|
|
54
|
+
):
|
|
55
|
+
async with USOSClient(api_base_address, consumer_key, consumer_secret) as client:
|
|
56
|
+
await client.load_access_token_from_file()
|
|
57
|
+
documentation_service = client.api_documentation_service
|
|
58
|
+
|
|
59
|
+
method_index = await documentation_service.get_method_index()
|
|
60
|
+
modules = set()
|
|
61
|
+
|
|
62
|
+
for method in method_index:
|
|
63
|
+
module = method.name.split("/")[1]
|
|
64
|
+
modules.add(module)
|
|
65
|
+
|
|
66
|
+
modules_info = []
|
|
67
|
+
for module in modules:
|
|
68
|
+
print(f"Fetching documentation for module {module}")
|
|
69
|
+
module_info = await documentation_service.get_module_info(module)
|
|
70
|
+
module_info = module_info.dict()
|
|
71
|
+
module_info["methods_info"] = {}
|
|
72
|
+
for method in module_info["methods"]:
|
|
73
|
+
print(f"Fetching documentation for method {method}")
|
|
74
|
+
method_info = await documentation_service.get_method_info(method)
|
|
75
|
+
module_info["methods_info"][method] = method_info.dict()
|
|
76
|
+
|
|
77
|
+
modules_info.append(module_info)
|
|
78
|
+
|
|
79
|
+
# Combine fetched data
|
|
80
|
+
documentation = {
|
|
81
|
+
"method_index": [method.dict() for method in method_index],
|
|
82
|
+
"modules": [module for module in modules_info],
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return documentation
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def save_documentation_to_file(file_path, documentation):
|
|
89
|
+
with open(file_path, "w") as file:
|
|
90
|
+
json.dump(documentation, file, indent=4)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
api_base_address = os.environ.get("USOS_API_BASE_ADDRESS", DEFAULT_API_BASE_ADDRESS)
|
|
95
|
+
consumer_key = os.environ.get("USOS_CONSUMER_KEY")
|
|
96
|
+
consumer_secret = os.environ.get("USOS_CONSUMER_SECRET")
|
|
97
|
+
|
|
98
|
+
if not consumer_key or not consumer_secret:
|
|
99
|
+
raise ValueError(
|
|
100
|
+
"Consumer key and secret must be set in the environment variables."
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
asyncio.run(fetch_data(api_base_address, consumer_key, consumer_secret))
|
|
104
|
+
# documentation = asyncio.run(fetch_documentation(api_base_address, consumer_key, consumer_secret))
|
|
105
|
+
# asyncio.run(save_documentation_to_file("usos_api_documentation.json", documentation))
|
|
@@ -101,7 +101,7 @@ class AuthManager:
|
|
|
101
101
|
self._request_token_secret = data["oauth_token_secret"]
|
|
102
102
|
self._oauth_client.resource_owner_key = self._request_token
|
|
103
103
|
self._oauth_client.resource_owner_secret = self._request_token_secret
|
|
104
|
-
_LOGGER.debug(
|
|
104
|
+
_LOGGER.debug("New request token generated")
|
|
105
105
|
|
|
106
106
|
async def get_authorization_url(
|
|
107
107
|
self, callback_url: str, confirm_user: bool = False
|
|
@@ -139,9 +139,7 @@ class AuthManager:
|
|
|
139
139
|
await self._handle_response_errors(response)
|
|
140
140
|
data = dict(urllib.parse.parse_qsl(await response.text()))
|
|
141
141
|
self.load_access_token(data["oauth_token"], data["oauth_token_secret"])
|
|
142
|
-
_LOGGER.debug(
|
|
143
|
-
f"Authorization successful, received access token"
|
|
144
|
-
)
|
|
142
|
+
_LOGGER.debug("Authorization successful, received access token")
|
|
145
143
|
return self.access_token, self.access_token_secret
|
|
146
144
|
except AttributeError as e:
|
|
147
145
|
if e.args[0] == "'NoneType' object has no attribute 'post'":
|