This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexample.py
66 lines (54 loc) · 2.33 KB
/
example.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
from life360 import life360
import datetime
#This is only here to make the example display nicer
def prettydate( d):
diff = datetime.datetime.utcnow() - d
s = diff.seconds
if diff.days > 7 or diff.days < 0:
return d.strftime('%d %b %y')
elif diff.days == 1:
return '1 day ago'
elif diff.days > 1:
return '{} days ago'.format(diff.days)
elif s <= 1:
return 'just now'
elif s < 60:
return '{} seconds ago'.format(s)
elif s < 120:
return '1 minute ago'
elif s < 3600:
return '{} minutes ago'.format(s/60)
elif s < 7200:
return '1 hour ago'
else:
return '{} hours ago'.format(s/3600)
if __name__ == "__main__":
# basic authorization hash (base64 if you want to decode it and see the sekrets)
# this is a googleable or sniffable value. i imagine life360 changes this sometimes.
# authorization_token = "cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=="
# updated token on 8/1/2023 @ryanbuckner
authorization_token = "Y2F0aGFwYWNyQVBoZUtVc3RlOGV2ZXZldnVjSGFmZVRydVl1ZnJhYzpkOEM5ZVlVdkE2dUZ1YnJ1SmVnZXRyZVZ1dFJlQ1JVWQ=="
# your username and password (hope they are secure!)
username = "[email protected]"
password = "super long password"
#instantiate the API
api = life360(authorization_token=authorization_token, username=username, password=password)
if api.authenticate():
#Grab some circles returns json
circles = api.get_circles()
#grab id
id = circles[0]['id']
#Let's get your circle!
circle = api.get_circle(id)
#Let's display some goodies
print("Circle name:", circle['name'])
print("Members (" + circle['memberCount'] + "):")
for m in circle['members']:
print("\tName:", m['firstName'], m['lastName'])
print("\tLocation:" , m['location']['name'])
print("\tLatLng:" , m['location']['latitude'] +", "+ m['location']['longitude'])
print("\tHas been at " + str(m['location']['name']) +" since " + prettydate(datetime.datetime.fromtimestamp(int(str(m['location']['since'])))))
print("\tBattery level:" , m['location']['battery'] +"%")
print("\t")
else:
print("Error authenticating")