-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zak.py
78 lines (61 loc) · 2.24 KB
/
zak.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import requests
import uuid
class ApiClient:
def __init__(self, app_version):
"""
:param app_version: Contains the version and build number of the Bank Cler Zak
app from the Google Play store as string in the following
format: 3.54.0.12168
"""
self.__scheme = 'https://'
self.__host = 'zak.prd.cler.ch'
self.__headers = {
'Accept-Language': 'de',
'Accept-Encoding': 'identity',
'ClientId': 'clerzakr7',
'User-Agent': 'Zak/' + app_version + ' (Android 14)',
'X-Zak-Device-Id': str(uuid.uuid4()),
'X-Same-Domain': 'forCsrfProtection',
'Connection': 'close'
}
self.__cookies = None
def __url(self, path):
return self.__scheme + self.__host + path
def __session_open(self):
response = requests.get(
url=self.__url('/public/api/open'),
headers=self.__headers,
cookies=self.__cookies
)
if not response.ok:
response.raise_for_status()
self._cookies = response.cookies
def __session_close(self):
response = requests.delete(url=self.__url('/auth/rest/public/authentication'))
if not response.ok:
response.raise_for_status()
self.__cookies = None
def __password_check(self, username, password):
response = requests.post(
url=self.__url('/auth/rest/public/authentication/password/check'),
json={'password': password, 'username': username},
headers=self.__headers,
cookies=self.__cookies
)
if not response.ok:
response.raise_for_status()
self.__cookies = response.cookies
def login(self, username, password):
self.__session_open()
self.__password_check(username, password)
def logout(self):
self.__session_close()
def transactions(self):
response = requests.get(
url=self.__url('/cler-ws-0.0.1/webapi/transaction'),
headers=self.__headers,
cookies=self.__cookies
)
if not response.ok:
response.raise_for_status()
return response.json()