-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_use.py
More file actions
executable file
·67 lines (53 loc) · 1.85 KB
/
example_use.py
File metadata and controls
executable file
·67 lines (53 loc) · 1.85 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# Install `python-dotenv` for this to work:
#
# from dotenv import load_dotenv
# load_dotenv()
from audkenni import see_some_id # Needs `load_dotenv()` before running.
from audkenni.exceptions import AuthException
from audkenni.exceptions import AuthInProgressException
from audkenni.exceptions import UserAbortedException
from audkenni.exceptions import TimeoutException
from audkenni.exceptions import WrongNumberException
from sys import argv
from sys import stderr
def usage():
print('Usage: ./example_use.py <phone-number> "<message>"')
print()
quit(1)
def parse_arguments(argv):
phone_number = ""
message = ""
try:
phone_number = argv[1]
message = argv[2]
except IndexError:
usage()
return phone_number, message
def main(argv):
phone_number, message = parse_arguments(argv)
try:
person = see_some_id(phone_number, message)
# Signature verification can optionally be skipped like so. It is not
# recommended, but some IDs don't seem to support them.
# person = see_some_id(phone_number, message, skip_signature_verification=True)
except AuthException:
print("Error: Authentication failed.")
quit(16)
except AuthInProgressException:
print("Error: Authentication already in progress.")
quit(32)
except UserAbortedException:
print("Error: The user aborted the operation.")
quit(4)
except TimeoutException:
print("Error: Operation timed out.")
quit(8)
except WrongNumberException:
print("Error: Phone number seems without a valid electronic ID.", file=stderr)
quit(2)
print("Name: %s" % person["name"])
print("SSN: %s" % person["nationalRegisterId"])
print("Signature: %s" % person["signature"])
if __name__ == "__main__":
main(argv)