pwd-client 3.0.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.
- pwd_client-3.0.0/LICENSE +7 -0
- pwd_client-3.0.0/PKG-INFO +47 -0
- pwd_client-3.0.0/README.md +29 -0
- pwd_client-3.0.0/pyproject.toml +34 -0
- pwd_client-3.0.0/src/pw_client/__init__.py +11 -0
- pwd_client-3.0.0/src/pw_client/core/__init__.py +0 -0
- pwd_client-3.0.0/src/pw_client/core/announcement/__init__.py +4 -0
- pwd_client-3.0.0/src/pw_client/core/announcement/constants.py +1 -0
- pwd_client-3.0.0/src/pw_client/core/announcement/endpoints.py +16 -0
- pwd_client-3.0.0/src/pw_client/core/announcement/parsers.py +26 -0
- pwd_client-3.0.0/src/pw_client/core/announcement/schemas.py +14 -0
- pwd_client-3.0.0/src/pw_client/core/announcement/service.py +16 -0
- pwd_client-3.0.0/src/pw_client/core/api.py +79 -0
- pwd_client-3.0.0/src/pw_client/core/auth/__init__.py +4 -0
- pwd_client-3.0.0/src/pw_client/core/auth/constants.py +5 -0
- pwd_client-3.0.0/src/pw_client/core/auth/endpoints.py +58 -0
- pwd_client-3.0.0/src/pw_client/core/auth/parsers.py +93 -0
- pwd_client-3.0.0/src/pw_client/core/auth/schema.py +26 -0
- pwd_client-3.0.0/src/pw_client/core/auth/service.py +30 -0
- pwd_client-3.0.0/src/pw_client/core/batch/__init__.py +19 -0
- pwd_client-3.0.0/src/pw_client/core/batch/constants.py +7 -0
- pwd_client-3.0.0/src/pw_client/core/batch/endpoints.py +81 -0
- pwd_client-3.0.0/src/pw_client/core/batch/parsers.py +348 -0
- pwd_client-3.0.0/src/pw_client/core/batch/schema.py +124 -0
- pwd_client-3.0.0/src/pw_client/core/batch/service.py +75 -0
- pwd_client-3.0.0/src/pw_client/core/clients/__init__.py +0 -0
- pwd_client-3.0.0/src/pw_client/core/clients/http.py +151 -0
- pwd_client-3.0.0/src/pw_client/core/config.py +21 -0
- pwd_client-3.0.0/src/pw_client/core/constants.py +59 -0
- pwd_client-3.0.0/src/pw_client/core/dashboard/__init__.py +4 -0
- pwd_client-3.0.0/src/pw_client/core/dashboard/constants.py +3 -0
- pwd_client-3.0.0/src/pw_client/core/dashboard/endpoints.py +41 -0
- pwd_client-3.0.0/src/pw_client/core/dashboard/parsers.py +78 -0
- pwd_client-3.0.0/src/pw_client/core/dashboard/schemas.py +40 -0
- pwd_client-3.0.0/src/pw_client/core/dashboard/service.py +28 -0
- pwd_client-3.0.0/src/pw_client/core/errors.py +63 -0
- pwd_client-3.0.0/src/pw_client/core/lifecycle.py +15 -0
- pwd_client-3.0.0/src/pw_client/core/quiz/__init__.py +4 -0
- pwd_client-3.0.0/src/pw_client/core/quiz/constants.py +2 -0
- pwd_client-3.0.0/src/pw_client/core/quiz/endpoints.py +19 -0
- pwd_client-3.0.0/src/pw_client/core/quiz/parsers.py +208 -0
- pwd_client-3.0.0/src/pw_client/core/quiz/schema.py +124 -0
- pwd_client-3.0.0/src/pw_client/core/quiz/service.py +20 -0
- pwd_client-3.0.0/src/pw_client/interfaces/__init__.py +0 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/__init__.py +0 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/__main__.py +5 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/app.py +46 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/deps.py +23 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/entry.py +26 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/errors.py +45 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/routes/__init__.py +0 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/routes/announcement.py +20 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/routes/auth.py +45 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/routes/batch.py +83 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/routes/dashboard.py +27 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/routes/quiz.py +28 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/routes/system.py +28 -0
- pwd_client-3.0.0/src/pw_client/interfaces/api/schema.py +14 -0
pwd_client-3.0.0/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 viraj-sh
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pwd-client
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Download Notes, DPPs and Quizes from pw.live
|
|
5
|
+
Author: viraj-sh
|
|
6
|
+
Author-email: viraj-sh <virajs45@proton.me>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: email-validator>=2.4.0
|
|
10
|
+
Requires-Dist: httpx>=0.29.0
|
|
11
|
+
Requires-Dist: pydantic>=2.14.4
|
|
12
|
+
Requires-Dist: pydantic-settings>=2.16.3
|
|
13
|
+
Requires-Dist: fastapi>=0.165.1 ; extra == 'api'
|
|
14
|
+
Requires-Dist: uvicorn>=0.55.0 ; extra == 'api'
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Provides-Extra: api
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
|
|
21
|
+
# Unofficial PW Client
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
A user-side client for **[pw.live](https://www.pw.live/)**, providing a streamlined interface to access officially enrolled course materials such as **Notes, DPPs, Quizzes, Announcements, and Solutions**.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### 📦 Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uv tool install 'pwd-client[api]'
|
|
35
|
+
```
|
|
36
|
+
Available commands: `pwapi`
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## **Disclaimer**
|
|
42
|
+
|
|
43
|
+
This project is intended **only for legitimate pw.live users**.
|
|
44
|
+
Users may access only the study material belonging to their own enrolled courses.
|
|
45
|
+
No unauthorized access, scraping, or misuse of pw.live systems is supported.
|
|
46
|
+
|
|
47
|
+
---
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Unofficial PW Client
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
A user-side client for **[pw.live](https://www.pw.live/)**, providing a streamlined interface to access officially enrolled course materials such as **Notes, DPPs, Quizzes, Announcements, and Solutions**.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
### 📦 Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv tool install 'pwd-client[api]'
|
|
17
|
+
```
|
|
18
|
+
Available commands: `pwapi`
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## **Disclaimer**
|
|
24
|
+
|
|
25
|
+
This project is intended **only for legitimate pw.live users**.
|
|
26
|
+
Users may access only the study material belonging to their own enrolled courses.
|
|
27
|
+
No unauthorized access, scraping, or misuse of pw.live systems is supported.
|
|
28
|
+
|
|
29
|
+
---
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pwd-client"
|
|
3
|
+
version = "3.0.0"
|
|
4
|
+
description = "Download Notes, DPPs and Quizes from pw.live"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "viraj-sh", email = "virajs45@proton.me" }]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"email-validator>=2.4.0",
|
|
12
|
+
"httpx>=0.29.0",
|
|
13
|
+
"pydantic>=2.14.4",
|
|
14
|
+
"pydantic-settings>=2.16.3",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.scripts]
|
|
18
|
+
pwapi = "pw_client.interfaces.api.entry:run"
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
api = ["fastapi>=0.165.1", "uvicorn>=0.55.0"]
|
|
22
|
+
|
|
23
|
+
[tool.ty.environment]
|
|
24
|
+
python = ".venv"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["uv_build>=0.11.21,<0.12.0"]
|
|
28
|
+
build-backend = "uv_build"
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = []
|
|
32
|
+
|
|
33
|
+
[tool.uv.build-backend]
|
|
34
|
+
module-name = "pw_client"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
|
|
3
|
+
from pw_client.core.api import App
|
|
4
|
+
from pw_client.core.errors import AppError
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
__version__ = version("pw-client")
|
|
8
|
+
except PackageNotFoundError:
|
|
9
|
+
__version__ = "0+unknown"
|
|
10
|
+
|
|
11
|
+
__all__ = ["App", "AppError", "__version__"]
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ANNOUNCEMENT_PATH = "/v1/batches/{batch_id}/announcement/v2"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
from pw_client.core.announcement.constants import ANNOUNCEMENT_PATH
|
|
4
|
+
from pw_client.core.clients.http import HTTPClient
|
|
5
|
+
from pw_client.core.constants import build_headers
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def announcement(
|
|
9
|
+
http: HTTPClient, *, token: str, batch_id: str, page: int = 1
|
|
10
|
+
) -> httpx.Response:
|
|
11
|
+
return await http.request(
|
|
12
|
+
"GET",
|
|
13
|
+
ANNOUNCEMENT_PATH.format(batch_id=batch_id),
|
|
14
|
+
params={"page": page},
|
|
15
|
+
headers=build_headers(token=token),
|
|
16
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
from pw_client.core.announcement.schemas import Annoucement
|
|
4
|
+
from pw_client.core.clients.http import read_json
|
|
5
|
+
from pw_client.core.errors import InvalidResponse
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def parse_annoucement(response: httpx.Response) -> list[Annoucement]:
|
|
9
|
+
data = read_json(response)
|
|
10
|
+
if response.status_code == 200:
|
|
11
|
+
return [
|
|
12
|
+
Annoucement(
|
|
13
|
+
id=ann.get("_id"),
|
|
14
|
+
heading=ann.get("heading"),
|
|
15
|
+
announcement=ann.get("announcement"),
|
|
16
|
+
type=ann.get("type"),
|
|
17
|
+
schedule_time=ann.get("scheduleTime"),
|
|
18
|
+
use_case=ann.get("announcementUseCase"),
|
|
19
|
+
url=f"{ann.get('attachment').get('baseUrl')}{ann.get('attachment').get('key')}",
|
|
20
|
+
)
|
|
21
|
+
for ann in data.get("data")
|
|
22
|
+
]
|
|
23
|
+
else:
|
|
24
|
+
raise InvalidResponse(
|
|
25
|
+
f"annoucement: invalid response {data.get('error').get('message')}"
|
|
26
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Annoucement(BaseModel):
|
|
7
|
+
model_config = ConfigDict(frozen=True)
|
|
8
|
+
id: str
|
|
9
|
+
heading: Optional[str] = Field(default=None)
|
|
10
|
+
announcement: Optional[str] = Field(default=None)
|
|
11
|
+
type: Optional[str] = Field(default=None)
|
|
12
|
+
schedule_time: Optional[str] = Field(default=None)
|
|
13
|
+
use_case: Optional[str] = Field(default=None)
|
|
14
|
+
url: Optional[str] = Field(default=None)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from pw_client.core.announcement import endpoints, parsers
|
|
2
|
+
from pw_client.core.announcement.schemas import Annoucement
|
|
3
|
+
from pw_client.core.clients.http import HTTPClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AnnouncementService:
|
|
7
|
+
def __init__(self, http: HTTPClient) -> None:
|
|
8
|
+
self._http = http
|
|
9
|
+
|
|
10
|
+
async def announcement(
|
|
11
|
+
self, *, token: str, batch_id: str, page: int = 1
|
|
12
|
+
) -> list[Annoucement]:
|
|
13
|
+
response = await endpoints.announcement(
|
|
14
|
+
self._http, token=token, batch_id=batch_id, page=page
|
|
15
|
+
)
|
|
16
|
+
return parsers.parse_annoucement(response)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from contextlib import AsyncExitStack
|
|
2
|
+
|
|
3
|
+
from pw_client.core import lifecycle
|
|
4
|
+
from pw_client.core.announcement.service import AnnouncementService
|
|
5
|
+
from pw_client.core.auth import AuthService
|
|
6
|
+
from pw_client.core.batch import BatchService
|
|
7
|
+
from pw_client.core.config import Settings
|
|
8
|
+
from pw_client.core.dashboard.service import DashboardService
|
|
9
|
+
from pw_client.core.errors import AppNotStarted
|
|
10
|
+
from pw_client.core.quiz.service import QuizService
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class App:
|
|
14
|
+
def __init__(self, config: Settings | None = None) -> None:
|
|
15
|
+
self.config = config or Settings()
|
|
16
|
+
self._stack = AsyncExitStack()
|
|
17
|
+
self._started = False
|
|
18
|
+
|
|
19
|
+
self._auth: AuthService | None = None
|
|
20
|
+
self._batch: BatchService | None = None
|
|
21
|
+
self._dashboard: DashboardService | None = None
|
|
22
|
+
self._quiz: QuizService | None = None
|
|
23
|
+
self._announcement: AnnouncementService | None = None
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def auth(self) -> AuthService:
|
|
27
|
+
if not self._started or self._auth is None:
|
|
28
|
+
raise AppNotStarted("App not started")
|
|
29
|
+
return self._auth
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def batch(self) -> BatchService:
|
|
33
|
+
if not self._started or self._batch is None:
|
|
34
|
+
raise AppNotStarted("App not started")
|
|
35
|
+
return self._batch
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def dashboard(self) -> DashboardService:
|
|
39
|
+
if not self._started or self._dashboard is None:
|
|
40
|
+
raise AppNotStarted("App not started")
|
|
41
|
+
return self._dashboard
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def quiz(self) -> QuizService:
|
|
45
|
+
if not self._started or self._quiz is None:
|
|
46
|
+
raise AppNotStarted("App not started")
|
|
47
|
+
return self._quiz
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def announcement(self) -> AnnouncementService:
|
|
51
|
+
if not self._started or self._announcement is None:
|
|
52
|
+
raise AppNotStarted("App not started")
|
|
53
|
+
return self._announcement
|
|
54
|
+
|
|
55
|
+
async def start(self) -> "App":
|
|
56
|
+
if self._started:
|
|
57
|
+
return self
|
|
58
|
+
try:
|
|
59
|
+
res = await lifecycle.start(self.config, self._stack)
|
|
60
|
+
except BaseException:
|
|
61
|
+
await self._stack.aclose()
|
|
62
|
+
raise
|
|
63
|
+
self._http = res.http
|
|
64
|
+
self._started = True
|
|
65
|
+
self._auth = AuthService(res.http)
|
|
66
|
+
self._batch = BatchService(res.http)
|
|
67
|
+
self._dashboard = DashboardService(res.http)
|
|
68
|
+
self._quiz = QuizService(res.http)
|
|
69
|
+
self._announcement = AnnouncementService(res.http)
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
async def close(self) -> None:
|
|
73
|
+
if self._started:
|
|
74
|
+
self._started = False
|
|
75
|
+
await self._stack.aclose()
|
|
76
|
+
|
|
77
|
+
async def health(self) -> dict[str, bool]:
|
|
78
|
+
http_ok = self._started and self._http.is_started
|
|
79
|
+
return {"http": http_ok}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from pydantic import Field
|
|
3
|
+
|
|
4
|
+
from pw_client.core.auth.constants import (
|
|
5
|
+
EXCHANGE_TOKEN_PATH,
|
|
6
|
+
LOGOUT_PATH,
|
|
7
|
+
REFRESH_TOKEN_PATH,
|
|
8
|
+
TOKEN_PATH,
|
|
9
|
+
VERIFY_TOKEN_PATH,
|
|
10
|
+
)
|
|
11
|
+
from pw_client.core.clients.http import HTTPClient
|
|
12
|
+
from pw_client.core.constants import ORGID, TOKEN_PAYLOAD_BASE, build_headers
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
async def token(
|
|
16
|
+
http: HTTPClient, *, mobile_no: str, otp: str = Field(min_length=6)
|
|
17
|
+
) -> httpx.Response:
|
|
18
|
+
return await http.request(
|
|
19
|
+
"POST",
|
|
20
|
+
TOKEN_PATH,
|
|
21
|
+
json={
|
|
22
|
+
"username": mobile_no,
|
|
23
|
+
"otp": otp,
|
|
24
|
+
"client_id": "system-admin",
|
|
25
|
+
"client_secret": ":",
|
|
26
|
+
"grant_type": "password",
|
|
27
|
+
"latitude": 0,
|
|
28
|
+
"longitude": 0,
|
|
29
|
+
"organizationId": ORGID,
|
|
30
|
+
},
|
|
31
|
+
headers=build_headers(),
|
|
32
|
+
idempotent=False,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
async def verify_token(http: HTTPClient, *, token: str) -> httpx.Response:
|
|
37
|
+
return await http.request(
|
|
38
|
+
"POST", VERIFY_TOKEN_PATH, headers=build_headers(token=token)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
async def refresh_token(http: HTTPClient, *, refresh_token: str) -> httpx.Response:
|
|
43
|
+
return await http.request(
|
|
44
|
+
"POST",
|
|
45
|
+
REFRESH_TOKEN_PATH,
|
|
46
|
+
json={**TOKEN_PAYLOAD_BASE, "refresh_token": refresh_token},
|
|
47
|
+
headers=build_headers(),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
async def exchange_token(http: HTTPClient, *, token: str) -> httpx.Response:
|
|
52
|
+
return await http.request(
|
|
53
|
+
"GET", EXCHANGE_TOKEN_PATH, headers=build_headers(token=token)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
async def logout(http: HTTPClient, *, token: str) -> httpx.Response:
|
|
58
|
+
return await http.request("POST", LOGOUT_PATH, headers=build_headers(token=token))
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
from pw_client.core.auth.schema import RefreshToken, Token, User
|
|
4
|
+
from pw_client.core.clients.http import read_json
|
|
5
|
+
from pw_client.core.errors import (
|
|
6
|
+
InvalidCredentials,
|
|
7
|
+
InvalidResponse,
|
|
8
|
+
PreconditionFailed,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_token(response: httpx.Response) -> Token:
|
|
13
|
+
data = read_json(response)
|
|
14
|
+
if response.status_code == 412:
|
|
15
|
+
raise PreconditionFailed(
|
|
16
|
+
f"token: unexpected status {response.status_code} -> {data.get('error').get('message') or {}}"
|
|
17
|
+
)
|
|
18
|
+
elif response.status_code == 200 and data.get("success") is True:
|
|
19
|
+
return Token(
|
|
20
|
+
access_token=data.get("data").get("access_token"),
|
|
21
|
+
refresh_token=data.get("data").get("refresh_token"),
|
|
22
|
+
expires_in=data.get("data").get("expires_in"),
|
|
23
|
+
user=User(
|
|
24
|
+
firstName=data.get("data").get("user").get("firstName"),
|
|
25
|
+
lastName=data.get("data").get("user").get("lastName"),
|
|
26
|
+
email=data.get("data").get("user").get("email"),
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
else:
|
|
30
|
+
raise InvalidResponse(
|
|
31
|
+
f"token: unexpected status {response.status_code} -> {data.get('error').get('message') or {}}"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def parse_verify_token(response: httpx.Response) -> bool:
|
|
36
|
+
if response.status_code not in (200, 401):
|
|
37
|
+
raise InvalidResponse(f"verify_token: unexpected status {response.status_code}")
|
|
38
|
+
data = read_json(response)
|
|
39
|
+
return response.status_code == 200 and data.get("success") is True
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def parse_refresh_token(response: httpx.Response) -> RefreshToken:
|
|
43
|
+
data = read_json(response)
|
|
44
|
+
if response.status_code == 412:
|
|
45
|
+
raise PreconditionFailed(
|
|
46
|
+
f"refresh_token: {response.status_code} -> {data.get('error').get('message') or {}}"
|
|
47
|
+
)
|
|
48
|
+
elif response.status_code == 401:
|
|
49
|
+
raise InvalidCredentials(
|
|
50
|
+
f"refresh_token: {response.status_code} -> {data.get('error').get('message') or {}}"
|
|
51
|
+
)
|
|
52
|
+
elif response.status_code == 200:
|
|
53
|
+
return RefreshToken(
|
|
54
|
+
access_token=data.get("data").get("access_token"),
|
|
55
|
+
refresh_token=data.get("data").get("refresh_token"),
|
|
56
|
+
expires_in=data.get("data").get("expires_in"),
|
|
57
|
+
)
|
|
58
|
+
else:
|
|
59
|
+
raise InvalidResponse(
|
|
60
|
+
f"refresh_token: {response.status_code} {response.status_code}"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def parse_exchange_token(response: httpx.Response) -> Token:
|
|
65
|
+
data = read_json(response)
|
|
66
|
+
if response.status_code == 412:
|
|
67
|
+
raise PreconditionFailed(
|
|
68
|
+
f"exchange_token: unexpected status {data.get('error').get('message') or {}}"
|
|
69
|
+
)
|
|
70
|
+
elif response.status_code == 401:
|
|
71
|
+
raise InvalidCredentials(
|
|
72
|
+
f"exchange_token: {data.get('error').get('message') or {}}"
|
|
73
|
+
)
|
|
74
|
+
elif response.status_code == 200 and data.get("success") is True:
|
|
75
|
+
return Token(
|
|
76
|
+
access_token=data.get("data").get("access_token"),
|
|
77
|
+
refresh_token=data.get("data").get("refresh_token"),
|
|
78
|
+
expires_in=data.get("data").get("expires_in"),
|
|
79
|
+
user=User(
|
|
80
|
+
firstName=data.get("data").get("user").get("firstName"),
|
|
81
|
+
lastName=data.get("data").get("user").get("lastName"),
|
|
82
|
+
email=data.get("data").get("user").get("email"),
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
else:
|
|
86
|
+
raise InvalidResponse(
|
|
87
|
+
f"exchange_token: unexpected status {response.status_code}"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def parse_logout(response: httpx.Response) -> bool:
|
|
92
|
+
data = read_json(response)
|
|
93
|
+
return response.status_code == 200 and data.get("success") is True
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, ConfigDict, EmailStr
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class User(BaseModel):
|
|
7
|
+
model_config = ConfigDict(frozen=True)
|
|
8
|
+
firstName: str
|
|
9
|
+
lastName: str
|
|
10
|
+
username: str | None = None
|
|
11
|
+
email: EmailStr
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Token(BaseModel):
|
|
15
|
+
model_config = ConfigDict(frozen=True)
|
|
16
|
+
access_token: str
|
|
17
|
+
refresh_token: str
|
|
18
|
+
expires_in: datetime | None = None
|
|
19
|
+
user: User
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RefreshToken(BaseModel):
|
|
23
|
+
model_config = ConfigDict(frozen=True)
|
|
24
|
+
access_token: str
|
|
25
|
+
refresh_token: str
|
|
26
|
+
expires_in: datetime | None = None
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from pw_client.core.auth import endpoints, parsers
|
|
2
|
+
from pw_client.core.auth.schema import RefreshToken, Token
|
|
3
|
+
from pw_client.core.clients.http import HTTPClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AuthService:
|
|
7
|
+
def __init__(self, http: HTTPClient) -> None:
|
|
8
|
+
self._http = http
|
|
9
|
+
|
|
10
|
+
async def token(self, *, mobile_no: str, otp: str) -> Token:
|
|
11
|
+
response = await endpoints.token(self._http, mobile_no=mobile_no, otp=otp)
|
|
12
|
+
return parsers.parse_token(response)
|
|
13
|
+
|
|
14
|
+
async def verify_token(self, *, token: str) -> bool:
|
|
15
|
+
response = await endpoints.verify_token(self._http, token=token)
|
|
16
|
+
return parsers.parse_verify_token(response)
|
|
17
|
+
|
|
18
|
+
async def refresh_token(self, *, refresh_token: str) -> RefreshToken:
|
|
19
|
+
response = await endpoints.refresh_token(
|
|
20
|
+
self._http, refresh_token=refresh_token
|
|
21
|
+
)
|
|
22
|
+
return parsers.parse_refresh_token(response)
|
|
23
|
+
|
|
24
|
+
async def exchange_token(self, *, token: str) -> Token:
|
|
25
|
+
response = await endpoints.exchange_token(self._http, token=token)
|
|
26
|
+
return parsers.parse_exchange_token(response)
|
|
27
|
+
|
|
28
|
+
async def logout(self, *, token: str) -> bool:
|
|
29
|
+
response = await endpoints.logout(self._http, token=token)
|
|
30
|
+
return parsers.parse_logout(response)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from pw_client.core.batch.schema import (
|
|
2
|
+
BatchDetail,
|
|
3
|
+
Batches,
|
|
4
|
+
Lecture,
|
|
5
|
+
Notes,
|
|
6
|
+
Quiz,
|
|
7
|
+
SubDetail,
|
|
8
|
+
)
|
|
9
|
+
from pw_client.core.batch.service import BatchService
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"BatchService",
|
|
13
|
+
"Batches",
|
|
14
|
+
"BatchDetail",
|
|
15
|
+
"SubDetail",
|
|
16
|
+
"Lecture",
|
|
17
|
+
"Notes",
|
|
18
|
+
"Quiz",
|
|
19
|
+
]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
BATCH_PATH = "/batch-service/v1/batches/purchased-batches"
|
|
2
|
+
BATCH_DETAILS_PATH = "/v3/batches/{batch_id}/details"
|
|
3
|
+
SUB_DETAILS_PATH = "/v2/batches/{batch_id}/subject/{sub_id}/topics"
|
|
4
|
+
CHAPTER_DETAILS_PATH = (
|
|
5
|
+
"/batch-service/v3/batch-subject-schedules/{batch_id}/subject/{sub_id}/contents"
|
|
6
|
+
)
|
|
7
|
+
DPP_LIST_PATH = "/v3/test-service/tests/new-dpp-list"
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from pw_client.core.batch.constants import (
|
|
7
|
+
BATCH_DETAILS_PATH,
|
|
8
|
+
BATCH_PATH,
|
|
9
|
+
CHAPTER_DETAILS_PATH,
|
|
10
|
+
DPP_LIST_PATH,
|
|
11
|
+
SUB_DETAILS_PATH,
|
|
12
|
+
)
|
|
13
|
+
from pw_client.core.clients.http import HTTPClient
|
|
14
|
+
from pw_client.core.constants import build_headers
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
async def batches(http: HTTPClient, *, token: str, page: int = 1) -> httpx.Response:
|
|
18
|
+
return await http.request(
|
|
19
|
+
"GET", BATCH_PATH, params={page: page}, headers=build_headers(token=token)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def batch_details(
|
|
24
|
+
http: HTTPClient, *, token: str, batch_id: str
|
|
25
|
+
) -> httpx.Response:
|
|
26
|
+
return await http.request(
|
|
27
|
+
"GET",
|
|
28
|
+
BATCH_DETAILS_PATH.format(batch_id=batch_id),
|
|
29
|
+
headers=build_headers(token=token),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def sub_details(
|
|
34
|
+
http: HTTPClient, *, token: str, batch_id: str, sub_id: str, page: int = 1
|
|
35
|
+
) -> httpx.Response:
|
|
36
|
+
return await http.request(
|
|
37
|
+
"GET",
|
|
38
|
+
SUB_DETAILS_PATH.format(batch_id=batch_id, sub_id=sub_id),
|
|
39
|
+
params={"page": page},
|
|
40
|
+
headers=build_headers(token=token),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def chapter_details(
|
|
45
|
+
http: HTTPClient,
|
|
46
|
+
*,
|
|
47
|
+
token: str,
|
|
48
|
+
batch_id: str,
|
|
49
|
+
sub_id: str,
|
|
50
|
+
chapter_id: str,
|
|
51
|
+
skip: int = 0,
|
|
52
|
+
limit: int = 20,
|
|
53
|
+
page: int = 1,
|
|
54
|
+
type: Literal["all", "notes", "lectures", "dpp_pdf", "dpp", "dpp_videos"] = "all",
|
|
55
|
+
) -> httpx.Response:
|
|
56
|
+
if type == "dpp":
|
|
57
|
+
url = DPP_LIST_PATH
|
|
58
|
+
params = {
|
|
59
|
+
"page": page,
|
|
60
|
+
"limit": limit,
|
|
61
|
+
"batchId": batch_id,
|
|
62
|
+
"batchSubjectId": sub_id,
|
|
63
|
+
"chapterId": chapter_id,
|
|
64
|
+
"dppType": "ALL",
|
|
65
|
+
}
|
|
66
|
+
else:
|
|
67
|
+
url = CHAPTER_DETAILS_PATH.format(batch_id=batch_id, sub_id=sub_id)
|
|
68
|
+
params = {
|
|
69
|
+
"skip": skip,
|
|
70
|
+
"limit": limit,
|
|
71
|
+
"contentType": type.upper(),
|
|
72
|
+
"tagId": chapter_id,
|
|
73
|
+
"contentFilter": "ALL",
|
|
74
|
+
}
|
|
75
|
+
return await http.request(
|
|
76
|
+
"GET", url=url, params=params, headers=build_headers(token=token)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async def download_document(http: HTTPClient, *, url: str, dest: Path) -> None:
|
|
81
|
+
await http.download_to_file(url, dest)
|