-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_db.py
103 lines (82 loc) · 3.1 KB
/
_db.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import requests
import pprint
from urllib.parse import quote
import base64
import json
if __name__ == '__main__':
simulator = True # FIX ME
site = 'simulator-api.db.com' if simulator else 'api.db.com'
redirect_uri = "" # FIX ME
redirect_uri_quote = quote(redirect_uri, safe='')
client_id = "" if simulator else "" # FIX ME
if simulator:
secret_key = "" # FIX ME
else:
secret_key = "" # FIX ME
state = "" # FIX ME
IBAN = "" if simulator else '' # FIX ME
step = 1
if step == 1:
url1 = f"https://{site}/gw/oidc/authorize?response_type=code&redirect_uri={redirect_uri_quote}&client_id={client_id}&state={state}"
print(url1)
if step == 2:
code = '' # FIX ME
base = base64.b64encode(f'{client_id}:{secret_key}'.encode("ascii"))
headers2 = {
"Authorization": f"Basic {base.decode('utf-8')}",
"Content-Type": "application/x-www-form-urlencoded"
}
data2 = {
"grant_type": "authorization_code",
"code": code,
"redirect_uri": redirect_uri
}
url2 = f"https://{site}/gw/oidc/token"
answer3 = requests.post(url2, headers=headers2, data=data2)
content = json.loads(answer3.content)
print(content['access_token'])
print(content['refresh_token'])
# with open('content.json', 'w') as file:
# file.write(json.dumps(content))
# with open('content.json', 'r') as file:
# content = json.loads(file.read())
content = {
"access_token": "", # FIX ME
"refresh_token": "" # FIX ME
}
if step == 3:
headers3 = {
"accept": "application/json",
"Authorization": f"Bearer {content['access_token']}"
}
url3 = f"https://{site}:443/gw/dbapi/banking/transactions/v2/"
url3 += f"?iban={IBAN}&sortBy=bookingDate%5BDESC%5D&limit=20&offset=0"
answer3 = requests.get(url3, headers=headers3)
if answer3.status_code == 200:
pprint.pprint(json.loads(answer3.text))
else:
print('refresh')
if step == 4:
refresh_url = f"https://{site}/gw/oidc/token"
refresh_headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
refresh_data = {
"grant_type": "refresh_token",
"client_id": client_id,
"client_secret": secret_key,
"refresh_token": content['refresh_token']
}
refresh_answer = requests.post(refresh_url, headers=refresh_headers, data=refresh_data)
new_content = json.loads(refresh_answer.content)
headers4 = {
"accept": "application/json",
"Authorization": f"Bearer {new_content['access_token']}"
}
url4 = f"https://{site}:443/gw/dbapi/banking/transactions/v2/"
url4 += f"?iban={IBAN}&sortBy=bookingDate%5BDESC%5D&limit=20&offset=0"
answer4 = requests.get(url4, headers=headers4)
if answer4.status_code == 200:
pprint.pprint(json.loads(answer4.text))
else:
print('xz')