-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathclear_callbacks.py
64 lines (52 loc) · 1.62 KB
/
clear_callbacks.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
import json
import sys
from lib import bunq
#from lib import bunq_api
from lib.config import config
config.load()
def print_notification_filter(nfs):
if not nfs:
print(" No callbacks")
return
for nfi in nfs:
nf = nfi["NotificationFilterUrl"]
print(' {} -> {}'.format(
nf["category"],
nf.get("notification_target", "-")))
def process_account(u, ac):
if ac["status"] != "ACTIVE":
return
print("Callbacks for account {} ({}):".format(
ac["id"], ac["description"]))
method = ("v1/user/{}/monetary-account/{}/" +
"notification-filter-url").format(u["id"], ac["id"])
nfs = bunq.get(method)
print_notification_filter(nfs)
if nfs:
print(" Removing callbacks...")
bunq.post(method, {
"notification_filters": []
})
def process_user(k, u):
if k == "UserApiKey":
name = next(iter(v["requested_by_user"].values()))["display_name"]
else:
name = u["display_name"]
print("Callbacks for user {}:".format(name))
method = "v1/user/{}/notification-filter-url".format(u["id"])
nfs = bunq.get(method)
print_notification_filter(nfs)
if nfs:
print(" Removing callbacks...")
bunq.post(method, {
"notification_filters": []
})
method = "v1/user/{}/monetary-account".format(u["id"])
for acs in bunq.get(method):
for ac in acs.values():
process_account(u, ac)
method = "v1/user"
users = bunq.get(method)
for u in users:
for k, v in u.items():
process_user(k, v)