-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathsample.py
executable file
·76 lines (63 loc) · 2.41 KB
/
sample.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
#!/usr/bin/env python
from argparse import ArgumentParser
import json
import eero
import six
class CookieStore(eero.SessionStorage):
def __init__(self, cookie_file):
from os import path
self.cookie_file = path.abspath(cookie_file)
try:
with open(self.cookie_file, 'r') as f:
self.__cookie = f.read()
except IOError:
self.__cookie = None
@property
def cookie(self):
return self.__cookie
@cookie.setter
def cookie(self, cookie):
self.__cookie = cookie
with open(self.cookie_file, 'w+') as f:
f.write(self.__cookie)
session = CookieStore('session.cookie')
eero = eero.Eero(session)
def print_json(data):
print(json.dumps(data, indent=4))
if __name__ == '__main__':
if eero.needs_login():
parser = ArgumentParser()
parser.add_argument("-l", help="your eero login (email address or phone number)")
args = parser.parse_args()
if args.l:
phone_number = args.l
else:
phone_number = six.moves.input('your eero login (email address or phone number): ')
user_token = eero.login(phone_number)
verification_code = six.moves.input('verification key from email or SMS: ')
eero.login_verify(verification_code, user_token)
print('Login successful. Rerun this command to get some output')
else:
account = eero.account()
parser = ArgumentParser()
parser.add_argument("command",
choices=['devices', 'details', 'info', 'eeros',
'reboot'],
help="info to print")
parser.add_argument("--eero", type=int, help="eero to reboot")
args = parser.parse_args()
for network in account['networks']['data']:
if args.command == 'info':
print_json(network)
if args.command == 'details':
network_details = eero.networks(network['url'])
print_json(network_details)
if args.command == 'devices':
devices = eero.devices(network['url'])
print_json(devices)
if args.command == 'eeros':
eeros = eero.eeros(network['url'])
print_json(eeros)
if args.command == 'reboot':
reboot = eero.reboot(args.eero)
print_json(reboot)