-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
51 lines (37 loc) · 1.76 KB
/
Copy pathquickstart.py
File metadata and controls
51 lines (37 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
"""Standalone SDK quickstart — read products and operations, no MCP, no agent.
Prerequisites: a saved profile. Create one fully in code (no CLI) with
examples/first_login.py. (Optional shortcuts also exist: `sber-unofficial enroll`,
or `sber-unofficial-mcp login` from the sber-unofficial-mcp package.)
Then run: python examples/quickstart.py ~/sber/profile.json
"""
from __future__ import annotations
import asyncio
import sys
from pathlib import Path
from sber_unofficial import AsyncSberClient, AuthenticationExpired
async def read(profile: Path, pin: str) -> None:
# from_pin_profile resumes the saved session and renews it via PIN only if the
# UFS session has expired. The client owns its transport, so use `async with`.
async with await AsyncSberClient.from_pin_profile(profile, pin=pin) as sber:
portfolio = await sber.portfolio()
print("Cards:")
for card in portfolio.cards:
print(f" {card.name} ••••{card.last4} {card.balance}") # balance: Money | None
print("Accounts:")
for acc in portfolio.accounts:
print(f" {acc.name} ••••{acc.last4} {acc.balance}")
print("Recent operations:")
for op in await sber.operations.list(limit=20):
print(f" {op.date} {op.amount} {op.description}")
def main() -> None:
if len(sys.argv) < 2:
sys.exit("usage: python examples/quickstart.py <profile.json> [pin]")
profile = Path(sys.argv[1]).expanduser()
pin = sys.argv[2] if len(sys.argv) > 2 else input("PIN: ")
try:
asyncio.run(read(profile, pin))
except AuthenticationExpired:
sys.exit("session expired and PIN re-login failed — re-run `enroll`/`login`")
if __name__ == "__main__":
main()