async-bakalari-api 0.3.2__tar.gz → 0.3.3__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.
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/PKG-INFO +30 -89
- async_bakalari_api-0.3.3/README.md +29 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/pyproject.toml +1 -1
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/requirements.txt +12 -11
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/PKG-INFO +30 -89
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/SOURCES.txt +4 -1
- async_bakalari_api-0.3.3/src/async_bakalari_api.egg-info/requires.txt +12 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/bakalari.py +8 -4
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/bakalari_demo.py +44 -11
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/const.py +5 -0
- async_bakalari_api-0.3.3/src/bakalari_api/logger_api.py +85 -0
- async_bakalari_api-0.3.3/src/bakalari_api/marks.py +522 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/tests/test_bakalari.py +43 -2
- async_bakalari_api-0.3.3/tests/test_logger.py +66 -0
- async_bakalari_api-0.3.3/tests/test_marks.py +488 -0
- async_bakalari_api-0.3.2/README.md +0 -88
- async_bakalari_api-0.3.2/src/async_bakalari_api.egg-info/requires.txt +0 -13
- async_bakalari_api-0.3.2/src/bakalari_api/logger_api.py +0 -61
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/LICENSE.md +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/setup.cfg +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/__init__.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/dependency_links.txt +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/entry_points.txt +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/not-zip-safe +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/top_level.txt +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/__init__.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/__main__.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/datastructure.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/exceptions.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/first_login.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/bakalari_api/komens.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/tests/test_const.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/tests/test_datastructure.py +0 -0
- {async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/tests/test_komens.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: async_bakalari_api
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Async API for Bakalari endpoint v3
|
|
5
5
|
Author-email: "Lukas Svoboda (@schizza)" <opensource@schizza.cz>
|
|
6
6
|
Maintainer-email: Lukas Svoboda <opensource@schizza.cz>
|
|
@@ -219,105 +219,46 @@ Classifier: Programming Language :: Python
|
|
|
219
219
|
Requires-Python: >=3.12
|
|
220
220
|
Description-Content-Type: text/markdown
|
|
221
221
|
License-File: LICENSE.md
|
|
222
|
-
Requires-Dist: aiofiles==
|
|
223
|
-
Requires-Dist: aiohttp==3.
|
|
224
|
-
Requires-Dist:
|
|
225
|
-
Requires-Dist:
|
|
226
|
-
Requires-Dist:
|
|
227
|
-
Requires-Dist: idna==3.7
|
|
222
|
+
Requires-Dist: aiofiles==24.1.0
|
|
223
|
+
Requires-Dist: aiohttp==3.12.15
|
|
224
|
+
Requires-Dist: attrs==24.2.0
|
|
225
|
+
Requires-Dist: frozenlist==1.7.0
|
|
226
|
+
Requires-Dist: idna==3.10
|
|
228
227
|
Requires-Dist: logger==1.4
|
|
229
|
-
Requires-Dist: multidict==6.0
|
|
230
|
-
Requires-Dist: orjson==3.10.
|
|
228
|
+
Requires-Dist: multidict==6.1.0
|
|
229
|
+
Requires-Dist: orjson==3.10.15
|
|
231
230
|
Requires-Dist: python-dateutil==2.9.0.post0
|
|
232
|
-
Requires-Dist: six==1.
|
|
231
|
+
Requires-Dist: six==1.17.0
|
|
233
232
|
Requires-Dist: strenum==0.4.15
|
|
234
|
-
Requires-Dist: yarl==1.
|
|
233
|
+
Requires-Dist: yarl==1.18.3
|
|
234
|
+
Dynamic: license-file
|
|
235
235
|
|
|
236
236
|
[](https://codecov.io/gh/schizza/async-bakalari-api3)
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
All notable changes to this project will be documented in this file.
|
|
238
|
+
[CHANGELOG](https://github.com/schizza/async-bakalari-api3/blob/main/CHANGELOG.md)
|
|
241
239
|
|
|
242
240
|
🇨🇿 Full documentation (czech) on [this site](https://async-bakalari-api.schizza.cz)
|
|
243
241
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
### Added
|
|
247
|
-
|
|
248
|
-
- `Schools` now support operations with towns
|
|
249
|
-
- new data structure `UniqueTowns` that hold all town names
|
|
250
|
-
- `get_town_partial_name` returns list of the towns based on partial name
|
|
251
|
-
- `get_all_towns returns` list of all towns
|
|
252
|
-
- `istown` checks if the town is present in the list
|
|
253
|
-
- `count_towns` returns number of towns in list
|
|
254
|
-
|
|
255
|
-
### Changed
|
|
256
|
-
|
|
257
|
-
dependency list is divided to application dependencies and development dependencies
|
|
258
|
-
|
|
259
|
-
## [0.3]
|
|
260
|
-
|
|
261
|
-
### Added
|
|
262
|
-
|
|
263
|
-
- `bakalari_demo.py` is now CLI application
|
|
264
|
-
- `Komens` now support for downloading attachment - `get_attachment`
|
|
265
|
-
- `send_auth_request` now supports extending EndPoints url wiht `extend` argument
|
|
266
|
-
- `school_list` now supports variable `town` - fetch schools in the town to limit downloading full list of schools.
|
|
267
|
-
- `Messages` class now have function `json` to return messages as JSON representative
|
|
268
|
-
- `Messages` class have `__str__` function for better handling `str(Messages)`
|
|
269
|
-
|
|
270
|
-
### Changed
|
|
271
|
-
|
|
272
|
-
- refactor of the code for speed and better reading of the code
|
|
273
|
-
- `school_list` now fetching schools in concurency mode - improved speed form about 1:30 min to 20s
|
|
274
|
-
- `mid` variable in the `MessageContainter` is now string instead of integer.
|
|
275
|
-
- `async_school_list` renamed to `school_list` as all methods are async
|
|
276
|
-
- `MessageContainter` returns JSON bytes on `as_json()` call instead of `orjson.Fragment`
|
|
277
|
-
- `get_messsages()` renamed to `fetch_messages()`
|
|
278
|
-
|
|
279
|
-
### Removed
|
|
280
|
-
|
|
281
|
-
- `username` from `Credentials` - as we do not need to store it
|
|
282
|
-
|
|
283
|
-
## [0.2]
|
|
284
|
-
|
|
285
|
-
### Added
|
|
286
|
-
|
|
287
|
-
- better exceptions handling and logging
|
|
288
|
-
- `class Komens`
|
|
289
|
-
- count unread messages
|
|
290
|
-
- get all messages
|
|
291
|
-
- tests and coverage
|
|
292
|
-
|
|
293
|
-
### Changed
|
|
294
|
-
|
|
295
|
-
- `async_schools_list` moved to `Bakalari` class
|
|
296
|
-
- Refactor login functions
|
|
297
|
-
- Refactor token handling
|
|
298
|
-
|
|
299
|
-
### Fixed
|
|
300
|
-
|
|
301
|
-
- Invalid refresh token
|
|
302
|
-
- Refactor send_request to better maintenance
|
|
303
|
-
|
|
304
|
-
## [0.0.1]
|
|
242
|
+
# async Bakalari API
|
|
305
243
|
|
|
306
|
-
|
|
244
|
+
Asynchronous client for schools involved to Bakalari API v3 endpoints.
|
|
307
245
|
|
|
308
|
-
|
|
246
|
+
***Still under development.***
|
|
309
247
|
|
|
310
|
-
|
|
311
|
-
- automatically refreshes access token with refresh token if refresh token is not expired
|
|
248
|
+
Features that are stable and working:
|
|
312
249
|
|
|
313
|
-
-
|
|
250
|
+
- CLI application `bakalari` available
|
|
314
251
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
252
|
+
- automatically login with cached `Credentials`
|
|
253
|
+
- fetching list of supported schools
|
|
254
|
+
|
|
255
|
+
- supports recursive search by town
|
|
256
|
+
- fetch all school or schools by town
|
|
257
|
+
|
|
258
|
+
- fetching messages
|
|
259
|
+
- unread messages
|
|
260
|
+
- all messages
|
|
261
|
+
- download attachments for fetched messages (with auto download support)
|
|
262
|
+
- search messages by ID, date, date range
|
|
318
263
|
|
|
319
|
-
|
|
320
|
-
[0.3.1]: https://https://github.com/schizza/bakalari-api3/releases/tag/0.3.1
|
|
321
|
-
[0.3]: https://https://github.com/schizza/bakalari-api3/releases/tag/0.3
|
|
322
|
-
[0.2]: https://github.com/schizza/bakalari-api3/releases/tag/0.2
|
|
323
|
-
[0.0.1]: https://github.com/schizza/bakalari-api3/releases/tag/v0.0.1
|
|
264
|
+
Any suggestions are welcomed.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[](https://codecov.io/gh/schizza/async-bakalari-api3)
|
|
2
|
+
|
|
3
|
+
[CHANGELOG](https://github.com/schizza/async-bakalari-api3/blob/main/CHANGELOG.md)
|
|
4
|
+
|
|
5
|
+
🇨🇿 Full documentation (czech) on [this site](https://async-bakalari-api.schizza.cz)
|
|
6
|
+
|
|
7
|
+
# async Bakalari API
|
|
8
|
+
|
|
9
|
+
Asynchronous client for schools involved to Bakalari API v3 endpoints.
|
|
10
|
+
|
|
11
|
+
***Still under development.***
|
|
12
|
+
|
|
13
|
+
Features that are stable and working:
|
|
14
|
+
|
|
15
|
+
- CLI application `bakalari` available
|
|
16
|
+
|
|
17
|
+
- automatically login with cached `Credentials`
|
|
18
|
+
- fetching list of supported schools
|
|
19
|
+
|
|
20
|
+
- supports recursive search by town
|
|
21
|
+
- fetch all school or schools by town
|
|
22
|
+
|
|
23
|
+
- fetching messages
|
|
24
|
+
- unread messages
|
|
25
|
+
- all messages
|
|
26
|
+
- download attachments for fetched messages (with auto download support)
|
|
27
|
+
- search messages by ID, date, date range
|
|
28
|
+
|
|
29
|
+
Any suggestions are welcomed.
|
|
@@ -4,33 +4,34 @@
|
|
|
4
4
|
#
|
|
5
5
|
# pip-compile
|
|
6
6
|
#
|
|
7
|
-
aiofiles==
|
|
7
|
+
aiofiles==24.1.0
|
|
8
8
|
# via -r requirements.in
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
aiohttp==3.12.15
|
|
11
|
+
|
|
12
|
+
|
|
10
13
|
# via -r requirements.in
|
|
11
|
-
|
|
14
|
+
attrs==24.2.0
|
|
12
15
|
# via aiohttp
|
|
13
|
-
|
|
14
|
-
# via aiohttp
|
|
15
|
-
frozenlist==1.4.1
|
|
16
|
+
frozenlist==1.7.0
|
|
16
17
|
# via
|
|
17
18
|
# aiohttp
|
|
18
19
|
# aiosignal
|
|
19
|
-
idna==3.
|
|
20
|
+
idna==3.10
|
|
20
21
|
# via yarl
|
|
21
22
|
logger==1.4
|
|
22
23
|
# via -r requirements.in
|
|
23
|
-
multidict==6.0
|
|
24
|
+
multidict==6.1.0
|
|
24
25
|
# via
|
|
25
26
|
# aiohttp
|
|
26
27
|
# yarl
|
|
27
|
-
orjson==3.10.
|
|
28
|
+
orjson==3.10.15
|
|
28
29
|
# via -r requirements.in
|
|
29
30
|
python-dateutil==2.9.0.post0
|
|
30
31
|
# via -r requirements.in
|
|
31
|
-
six==1.
|
|
32
|
+
six==1.17.0
|
|
32
33
|
# via python-dateutil
|
|
33
34
|
strenum==0.4.15
|
|
34
35
|
# via -r requirements.in
|
|
35
|
-
yarl==1.
|
|
36
|
+
yarl==1.18.3
|
|
36
37
|
# via aiohttp
|
{async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: async_bakalari_api
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Async API for Bakalari endpoint v3
|
|
5
5
|
Author-email: "Lukas Svoboda (@schizza)" <opensource@schizza.cz>
|
|
6
6
|
Maintainer-email: Lukas Svoboda <opensource@schizza.cz>
|
|
@@ -219,105 +219,46 @@ Classifier: Programming Language :: Python
|
|
|
219
219
|
Requires-Python: >=3.12
|
|
220
220
|
Description-Content-Type: text/markdown
|
|
221
221
|
License-File: LICENSE.md
|
|
222
|
-
Requires-Dist: aiofiles==
|
|
223
|
-
Requires-Dist: aiohttp==3.
|
|
224
|
-
Requires-Dist:
|
|
225
|
-
Requires-Dist:
|
|
226
|
-
Requires-Dist:
|
|
227
|
-
Requires-Dist: idna==3.7
|
|
222
|
+
Requires-Dist: aiofiles==24.1.0
|
|
223
|
+
Requires-Dist: aiohttp==3.12.15
|
|
224
|
+
Requires-Dist: attrs==24.2.0
|
|
225
|
+
Requires-Dist: frozenlist==1.7.0
|
|
226
|
+
Requires-Dist: idna==3.10
|
|
228
227
|
Requires-Dist: logger==1.4
|
|
229
|
-
Requires-Dist: multidict==6.0
|
|
230
|
-
Requires-Dist: orjson==3.10.
|
|
228
|
+
Requires-Dist: multidict==6.1.0
|
|
229
|
+
Requires-Dist: orjson==3.10.15
|
|
231
230
|
Requires-Dist: python-dateutil==2.9.0.post0
|
|
232
|
-
Requires-Dist: six==1.
|
|
231
|
+
Requires-Dist: six==1.17.0
|
|
233
232
|
Requires-Dist: strenum==0.4.15
|
|
234
|
-
Requires-Dist: yarl==1.
|
|
233
|
+
Requires-Dist: yarl==1.18.3
|
|
234
|
+
Dynamic: license-file
|
|
235
235
|
|
|
236
236
|
[](https://codecov.io/gh/schizza/async-bakalari-api3)
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
All notable changes to this project will be documented in this file.
|
|
238
|
+
[CHANGELOG](https://github.com/schizza/async-bakalari-api3/blob/main/CHANGELOG.md)
|
|
241
239
|
|
|
242
240
|
🇨🇿 Full documentation (czech) on [this site](https://async-bakalari-api.schizza.cz)
|
|
243
241
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
### Added
|
|
247
|
-
|
|
248
|
-
- `Schools` now support operations with towns
|
|
249
|
-
- new data structure `UniqueTowns` that hold all town names
|
|
250
|
-
- `get_town_partial_name` returns list of the towns based on partial name
|
|
251
|
-
- `get_all_towns returns` list of all towns
|
|
252
|
-
- `istown` checks if the town is present in the list
|
|
253
|
-
- `count_towns` returns number of towns in list
|
|
254
|
-
|
|
255
|
-
### Changed
|
|
256
|
-
|
|
257
|
-
dependency list is divided to application dependencies and development dependencies
|
|
258
|
-
|
|
259
|
-
## [0.3]
|
|
260
|
-
|
|
261
|
-
### Added
|
|
262
|
-
|
|
263
|
-
- `bakalari_demo.py` is now CLI application
|
|
264
|
-
- `Komens` now support for downloading attachment - `get_attachment`
|
|
265
|
-
- `send_auth_request` now supports extending EndPoints url wiht `extend` argument
|
|
266
|
-
- `school_list` now supports variable `town` - fetch schools in the town to limit downloading full list of schools.
|
|
267
|
-
- `Messages` class now have function `json` to return messages as JSON representative
|
|
268
|
-
- `Messages` class have `__str__` function for better handling `str(Messages)`
|
|
269
|
-
|
|
270
|
-
### Changed
|
|
271
|
-
|
|
272
|
-
- refactor of the code for speed and better reading of the code
|
|
273
|
-
- `school_list` now fetching schools in concurency mode - improved speed form about 1:30 min to 20s
|
|
274
|
-
- `mid` variable in the `MessageContainter` is now string instead of integer.
|
|
275
|
-
- `async_school_list` renamed to `school_list` as all methods are async
|
|
276
|
-
- `MessageContainter` returns JSON bytes on `as_json()` call instead of `orjson.Fragment`
|
|
277
|
-
- `get_messsages()` renamed to `fetch_messages()`
|
|
278
|
-
|
|
279
|
-
### Removed
|
|
280
|
-
|
|
281
|
-
- `username` from `Credentials` - as we do not need to store it
|
|
282
|
-
|
|
283
|
-
## [0.2]
|
|
284
|
-
|
|
285
|
-
### Added
|
|
286
|
-
|
|
287
|
-
- better exceptions handling and logging
|
|
288
|
-
- `class Komens`
|
|
289
|
-
- count unread messages
|
|
290
|
-
- get all messages
|
|
291
|
-
- tests and coverage
|
|
292
|
-
|
|
293
|
-
### Changed
|
|
294
|
-
|
|
295
|
-
- `async_schools_list` moved to `Bakalari` class
|
|
296
|
-
- Refactor login functions
|
|
297
|
-
- Refactor token handling
|
|
298
|
-
|
|
299
|
-
### Fixed
|
|
300
|
-
|
|
301
|
-
- Invalid refresh token
|
|
302
|
-
- Refactor send_request to better maintenance
|
|
303
|
-
|
|
304
|
-
## [0.0.1]
|
|
242
|
+
# async Bakalari API
|
|
305
243
|
|
|
306
|
-
|
|
244
|
+
Asynchronous client for schools involved to Bakalari API v3 endpoints.
|
|
307
245
|
|
|
308
|
-
|
|
246
|
+
***Still under development.***
|
|
309
247
|
|
|
310
|
-
|
|
311
|
-
- automatically refreshes access token with refresh token if refresh token is not expired
|
|
248
|
+
Features that are stable and working:
|
|
312
249
|
|
|
313
|
-
-
|
|
250
|
+
- CLI application `bakalari` available
|
|
314
251
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
252
|
+
- automatically login with cached `Credentials`
|
|
253
|
+
- fetching list of supported schools
|
|
254
|
+
|
|
255
|
+
- supports recursive search by town
|
|
256
|
+
- fetch all school or schools by town
|
|
257
|
+
|
|
258
|
+
- fetching messages
|
|
259
|
+
- unread messages
|
|
260
|
+
- all messages
|
|
261
|
+
- download attachments for fetched messages (with auto download support)
|
|
262
|
+
- search messages by ID, date, date range
|
|
318
263
|
|
|
319
|
-
|
|
320
|
-
[0.3.1]: https://https://github.com/schizza/bakalari-api3/releases/tag/0.3.1
|
|
321
|
-
[0.3]: https://https://github.com/schizza/bakalari-api3/releases/tag/0.3
|
|
322
|
-
[0.2]: https://github.com/schizza/bakalari-api3/releases/tag/0.2
|
|
323
|
-
[0.0.1]: https://github.com/schizza/bakalari-api3/releases/tag/v0.0.1
|
|
264
|
+
Any suggestions are welcomed.
|
{async_bakalari_api-0.3.2 → async_bakalari_api-0.3.3}/src/async_bakalari_api.egg-info/SOURCES.txt
RENAMED
|
@@ -20,7 +20,10 @@ src/bakalari_api/exceptions.py
|
|
|
20
20
|
src/bakalari_api/first_login.py
|
|
21
21
|
src/bakalari_api/komens.py
|
|
22
22
|
src/bakalari_api/logger_api.py
|
|
23
|
+
src/bakalari_api/marks.py
|
|
23
24
|
tests/test_bakalari.py
|
|
24
25
|
tests/test_const.py
|
|
25
26
|
tests/test_datastructure.py
|
|
26
|
-
tests/test_komens.py
|
|
27
|
+
tests/test_komens.py
|
|
28
|
+
tests/test_logger.py
|
|
29
|
+
tests/test_marks.py
|
|
@@ -64,11 +64,14 @@ class Bakalari:
|
|
|
64
64
|
# Close connection when this object is destroyed
|
|
65
65
|
try:
|
|
66
66
|
loop = asyncio.get_event_loop()
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
except RuntimeError:
|
|
68
|
+
loop = asyncio.new_event_loop()
|
|
69
|
+
asyncio.set_event_loop(loop)
|
|
70
|
+
|
|
71
|
+
if loop.is_running():
|
|
72
|
+
return loop.create_task(self.session.close())
|
|
73
|
+
else:
|
|
69
74
|
loop.run_until_complete(self.session.close())
|
|
70
|
-
finally:
|
|
71
|
-
pass
|
|
72
75
|
|
|
73
76
|
async def send_auth_request(
|
|
74
77
|
self, request_endpoint: EndPoint, extend: str | None = None, **kwargs
|
|
@@ -411,6 +414,7 @@ class Bakalari:
|
|
|
411
414
|
try:
|
|
412
415
|
with open(filename, "wb") as file:
|
|
413
416
|
file.write(orjson.dumps(self.credentials, option=orjson.OPT_INDENT_2))
|
|
417
|
+
log.debug(f"Credentials saved to file {filename}")
|
|
414
418
|
except OSError as err:
|
|
415
419
|
log.error(f"Error while saving credentials to file {filename}. {str(err)}")
|
|
416
420
|
return False
|
|
@@ -18,6 +18,7 @@ async def w(name, data):
|
|
|
18
18
|
async with aiofiles.open(name, "+wb") as fi:
|
|
19
19
|
await fi.write(orjson.dumps(data, option=orjson.OPT_INDENT_2))
|
|
20
20
|
await fi.flush()
|
|
21
|
+
logging.debug(f"File {name} written")
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
async def wb(name, data):
|
|
@@ -25,6 +26,7 @@ async def wb(name, data):
|
|
|
25
26
|
async with aiofiles.open(name, "wb") as fi:
|
|
26
27
|
await fi.write(data)
|
|
27
28
|
await fi.flush()
|
|
29
|
+
logging.debug(f"File {name} written")
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
def r(name):
|
|
@@ -87,7 +89,7 @@ async def komens(args, bakalari):
|
|
|
87
89
|
tasks = []
|
|
88
90
|
for msg in messages:
|
|
89
91
|
print(str(msg))
|
|
90
|
-
tasks = create_attachment_task(msg)
|
|
92
|
+
tasks = await create_attachment_task(msg)
|
|
91
93
|
|
|
92
94
|
asyncio.gather(*tasks)
|
|
93
95
|
|
|
@@ -128,21 +130,38 @@ async def komens(args, bakalari):
|
|
|
128
130
|
|
|
129
131
|
async def runme(args):
|
|
130
132
|
"""Run the main function."""
|
|
133
|
+
server = False
|
|
134
|
+
schools = False
|
|
131
135
|
|
|
132
|
-
if args.
|
|
136
|
+
if args.config and not args.first_login and not args.first_login_file:
|
|
137
|
+
try:
|
|
138
|
+
async with aiofiles.open("config.json", "rb") as fi:
|
|
139
|
+
data = await fi.read()
|
|
140
|
+
try:
|
|
141
|
+
data = orjson.loads(data)
|
|
142
|
+
except Exception as ex:
|
|
143
|
+
print(f"Neplatný konfigurační soubor. ({ex})")
|
|
144
|
+
os._exit(1)
|
|
145
|
+
server = data["school"]
|
|
146
|
+
args.auto_cache = "credentials.json"
|
|
147
|
+
except FileNotFoundError:
|
|
148
|
+
print("Konfigurační soubor nenalezen.")
|
|
149
|
+
os._exit(1)
|
|
150
|
+
|
|
151
|
+
if args.sf and not server:
|
|
133
152
|
try:
|
|
134
153
|
schools: Schools = await Schools().load_from_file(args.sf)
|
|
135
154
|
except Exception as ex:
|
|
136
155
|
os._exit(ex)
|
|
137
|
-
|
|
156
|
+
elif not server:
|
|
138
157
|
schools: Schools = await Bakalari().schools_list(town=args.town)
|
|
139
158
|
|
|
140
|
-
if not schools:
|
|
159
|
+
if not schools and not args.config:
|
|
141
160
|
print("Nenalezeny žádné školy")
|
|
142
161
|
os._exit(1)
|
|
143
162
|
|
|
144
163
|
school = args.school
|
|
145
|
-
if school:
|
|
164
|
+
if school and not server:
|
|
146
165
|
server = schools.get_url(school)
|
|
147
166
|
|
|
148
167
|
if args.no_login:
|
|
@@ -166,12 +185,17 @@ async def runme(args):
|
|
|
166
185
|
|
|
167
186
|
credentials = await bakalari.first_login(login, passw)
|
|
168
187
|
|
|
169
|
-
if args.credentials_file:
|
|
170
|
-
w(args.credentials_file, credentials)
|
|
171
|
-
|
|
188
|
+
if args.credentials_file and not args.config:
|
|
189
|
+
await w(args.credentials_file, credentials)
|
|
190
|
+
elif not args.config and not cache:
|
|
172
191
|
print(
|
|
173
192
|
f"Access token: {credentials.access_token}\nRefresh token: {credentials.refresh_token}"
|
|
174
193
|
)
|
|
194
|
+
if args.config:
|
|
195
|
+
await w("config.json", {"school": server})
|
|
196
|
+
await w("credentials.json", credentials)
|
|
197
|
+
if cache:
|
|
198
|
+
bakalari.save_credentials()
|
|
175
199
|
|
|
176
200
|
print(
|
|
177
201
|
f"Cahce: {bakalari.auto_cache_credentials} cache_filename={bakalari.cache_filename} server: {bakalari.server}"
|
|
@@ -183,7 +207,9 @@ async def runme(args):
|
|
|
183
207
|
bakalari.credentials.access_token = credentials["access_token"]
|
|
184
208
|
bakalari.credentials.refresh_token = credentials["refresh_token"]
|
|
185
209
|
|
|
186
|
-
if args.auto_cache
|
|
210
|
+
if args.auto_cache and not (
|
|
211
|
+
args.first_login or args.first_login_file or args.credentials
|
|
212
|
+
):
|
|
187
213
|
bakalari = Bakalari(
|
|
188
214
|
server=server, auto_cache_credentials=True, cache_filename=args.auto_cache
|
|
189
215
|
)
|
|
@@ -201,7 +227,7 @@ def main() -> None:
|
|
|
201
227
|
parser_login = parser.add_argument_group(
|
|
202
228
|
"Přihlášení (požadováno)", "Zvolte typ přihlášení heslo / tokenu"
|
|
203
229
|
)
|
|
204
|
-
login_type = parser_login.add_mutually_exclusive_group(
|
|
230
|
+
login_type = parser_login.add_mutually_exclusive_group()
|
|
205
231
|
|
|
206
232
|
login_type.add_argument(
|
|
207
233
|
"-N", "--no_login", action="store_true", help="Provede neautorizovaný přístup"
|
|
@@ -240,7 +266,14 @@ def main() -> None:
|
|
|
240
266
|
help="Jméno souboru odkud se maji načíst tokeny.",
|
|
241
267
|
)
|
|
242
268
|
|
|
243
|
-
|
|
269
|
+
parser_login.add_argument(
|
|
270
|
+
"-a",
|
|
271
|
+
"--auto",
|
|
272
|
+
help="Při úspěšném přihlášení jménem a heslem uloží tokeny a název školy do konfiguračních souborů a později je použije k automatickému přihlášení.",
|
|
273
|
+
action="store_true",
|
|
274
|
+
dest="config",
|
|
275
|
+
)
|
|
276
|
+
parser_login.add_argument(
|
|
244
277
|
"--auto_cache",
|
|
245
278
|
nargs=None,
|
|
246
279
|
dest="auto_cache",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Bakalari API logger."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import logging.handlers
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CustomFormatter(logging.Formatter):
|
|
8
|
+
"""Custom formater for module."""
|
|
9
|
+
|
|
10
|
+
black = "\u001b[30m"
|
|
11
|
+
yellow = "\u001b[33m"
|
|
12
|
+
red = "\u001b[31m"
|
|
13
|
+
bold_red = "\x1b[31;1m"
|
|
14
|
+
reset = "\u001b[0m"
|
|
15
|
+
green = "\u001b[32m"
|
|
16
|
+
grey = "\u001b[30m"
|
|
17
|
+
blue = "\u001b[34m"
|
|
18
|
+
magenta = "\u001b[35m"
|
|
19
|
+
cyan = "\u001b[36m"
|
|
20
|
+
white = "\u001b[37m"
|
|
21
|
+
|
|
22
|
+
_format = f"%(asctime)s - %(name)s - %(levelname)s - %(threadName)s:\n {cyan}Message: %(message)s\n{magenta}@(%(filename)s:%(lineno)d)"
|
|
23
|
+
dateformat = "%d/%m/%Y %H:%M:%S"
|
|
24
|
+
|
|
25
|
+
FORMATS = {
|
|
26
|
+
logging.DEBUG: grey + _format + reset,
|
|
27
|
+
logging.INFO: green + _format + reset,
|
|
28
|
+
logging.WARNING: yellow + _format + reset,
|
|
29
|
+
logging.ERROR: bold_red + _format + reset,
|
|
30
|
+
logging.CRITICAL: bold_red + _format + reset,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def format(self, record):
|
|
34
|
+
"""Format string."""
|
|
35
|
+
|
|
36
|
+
log_fmt = self.FORMATS.get(record.levelno)
|
|
37
|
+
formatter = logging.Formatter(log_fmt, datefmt=self.dateformat)
|
|
38
|
+
return formatter.format(record)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class api_logger:
|
|
42
|
+
"""API logger."""
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def create(cls, name, loglevel: int = logging.ERROR):
|
|
46
|
+
"""Create API logger."""
|
|
47
|
+
instance = cls(name, loglevel)
|
|
48
|
+
return instance.logger
|
|
49
|
+
|
|
50
|
+
def __init__(self, name, loglevel: int = logging.ERROR):
|
|
51
|
+
"""Create API logger."""
|
|
52
|
+
self.name = name
|
|
53
|
+
self.loglevel = loglevel
|
|
54
|
+
|
|
55
|
+
self.console_formatter = CustomFormatter()
|
|
56
|
+
self.logger = logging.getLogger(name)
|
|
57
|
+
|
|
58
|
+
# Reuse existing stream handler if present; avoid duplicates
|
|
59
|
+
stream_handler = None
|
|
60
|
+
for h in self.logger.handlers:
|
|
61
|
+
if isinstance(h, logging.StreamHandler):
|
|
62
|
+
stream_handler = h
|
|
63
|
+
break
|
|
64
|
+
if stream_handler is None:
|
|
65
|
+
stream_handler = logging.StreamHandler()
|
|
66
|
+
self.logger.addHandler(stream_handler)
|
|
67
|
+
|
|
68
|
+
# Expose handler on instance
|
|
69
|
+
self.console_logger = stream_handler
|
|
70
|
+
|
|
71
|
+
# Always use our formatter and let logger level control filtering
|
|
72
|
+
stream_handler.setFormatter(self.console_formatter)
|
|
73
|
+
stream_handler.setLevel(logging.NOTSET)
|
|
74
|
+
|
|
75
|
+
# Prefer the most verbose (lowest) level across repeated initializations
|
|
76
|
+
current_level = self.logger.level
|
|
77
|
+
if current_level == logging.NOTSET:
|
|
78
|
+
new_level = loglevel
|
|
79
|
+
else:
|
|
80
|
+
new_level = min(current_level, loglevel)
|
|
81
|
+
self.logger.setLevel(new_level)
|
|
82
|
+
|
|
83
|
+
def get(self):
|
|
84
|
+
"Get."
|
|
85
|
+
return self.logger
|