Skip to content

Instantly share code, notes, and snippets.

@featherbear
Created October 27, 2020 18:13
Show Gist options
  • Save featherbear/2fa6c7113166a00df2477dcb99e6fc30 to your computer and use it in GitHub Desktop.
Save featherbear/2fa6c7113166a00df2477dcb99e6fc30 to your computer and use it in GitHub Desktop.
life360_username="---"
life360_password="---"
import requests
urlPrefix = "https://api.life360.com/v3/"
print("Authorising...")
auth = requests.post(urlPrefix + "oauth2/token.json",headers=dict(Authorization="Basic cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=="), data=dict(grant_type="password",username=life360_username,password=life360_password))
assert auth.status_code ==200
life360_me = auth.json()["user"]["id"]
auth = auth.json()["access_token"]
def request(url, data=None):
req_url = urlPrefix + url
req_header = dict(Authorization="Bearer %s" % auth)
req = requests.post(req_url, headers=req_header, data=data) if data else requests.get(req_url, headers=req_header)
return req.json() if req.status_code==200 else None
print("Fetching circles...")
circles = request("circles.json")["circles"]
getUser = lambda circle=circles[0]["id"], member=life360_me: request("circles/%s/members/%s" % (circle,member))
parseLocationData = lambda l: dict(lat=l["latitude"],long=l["longitude"],since=l["since"],last=l["timestamp"],name=l["name"],battery=l["battery"])
print("Retrieving user's location...")
location = parseLocationData(getUser()["location"])
def reverseGeocode(lat,long):
req = requests.get("http://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&sensor=false" % (lat,long)).json()
return req["results"][0]["formatted_address"] if req["status"] == "OK" else None
print("Location: " + (location["name"] if location["name"] else reverseGeocode(location["lat"], location["long"])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment