-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.py
49 lines (40 loc) · 1.92 KB
/
consumer.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
import ldnlib
import argparse
import json
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="""For a provided web
resource, discover an ldp:inbox and GET the notifications from
that inbox, if one exists""")
parser.add_argument("target", help="The IRI of the target web resource")
parser.add_argument("--target_username",
help="The username for the target resource")
parser.add_argument("--target_password",
help="The password for the target resource")
parser.add_argument("--inbox_username",
help="The username for the inbox resource")
parser.add_argument("--inbox_password",
help="The password for the inbox resource")
parser.add_argument("--allow_local_inbox", type=bool, default=False,
help="Whether to allow a local inbox address")
args = parser.parse_args()
target_auth = None
if args.target_username and args.target_password:
target_auth = (args.target_username, args.target_password)
inbox_auth = None
if args.inbox_username and args.inbox_password:
inbox_auth = (args.inbox_username, args.inbox_password)
consumer = ldnlib.Consumer()
inbox = consumer.discover(args.target, auth=target_auth)
if inbox is not None:
print("Found inbox: {}".format(inbox))
notifications = consumer.notifications(inbox, auth=inbox_auth)
print("Found {0} notifications: {1}".format(len(notifications),
" ".join(notifications)))
for iri in notifications:
print("")
print("IRI: {}".format(iri))
notification = consumer.notification(iri, auth=inbox_auth)
print("Notification: {}".format(json.dumps(notification,
ensure_ascii=False)))
else:
print("Sorry, no inbox defined for the resource")