Skip to content

Instantly share code, notes, and snippets.

@nbonfire
Created May 20, 2019 15:49
Show Gist options
  • Save nbonfire/f6cc9cb91859b1e5bc4351c36a3517b6 to your computer and use it in GitHub Desktop.
Save nbonfire/f6cc9cb91859b1e5bc4351c36a3517b6 to your computer and use it in GitHub Desktop.
MySubaru python samples
import requests, json
from subarucreds import username,password,pin # just a "subarucreds.py" that has some variables i didn't want to share
import datetime
#login
s=requests.Session()
loginr=s.post('https://www.mysubaru.com/login', data = {'username':username,'password':password})
#should return a response 200
#Where's my subaru?
ts = str(int(datetime.datetime.now().timestamp()))
locateurl='https://www.mysubaru.com/service/g2/refreshVehicleStatus/execute.json'
data={'now':ts,'pin':pin,'horn':'true','unlockDoorType':'FRONT_LEFT_DOOR_CMD'}
locater=s.post(locateurl,data=data)
locate_json=locater.json()
if locate_json['success']==True and locate_json['data']['success'] == False:
request_id=locater.json()['data']['serviceRequestId']
print(request_id)
checkLocateUrl='https://www.mysubaru.com/service/g2/locate/execute.json'
data={'serviceRequestId':request_id}
locationStatusr=s.post(checkLocateUrl,data=data)
status_json=locationStatusr.json()
while status_json['data']['success'] is not True:
locationStatusr=s.post(checkLocateUrl,data=data)
status_json=locationStatusr.json()
print(status_json['data']['result'])
#unlock doors
unlockUrl='https://www.mysubaru.com/service/g2/unlock/execute.json'
ts = str(int(datetime.datetime.now().timestamp()))
data={'now':ts,'pin':pin,'horn':'true','unlockDoorType':'FRONT_LEFT_DOOR_CMD'}
unlock=s.post(unlockUrl,data=data)
unlock.json()
unlock_json=unlock.json()
unlock_request_id=unlock_json['data']['serviceRequestId']
statusUrl='https://www.mysubaru.com/service/g2/remoteService/status.json'
while unlock_json['data']['success'] is not True:
unlockStatus=s.post(statusUrl,data={'serviceRequestId':unlock_request_id})
unlock_json=unlockStatus.json()
unlock_request_id=unlock_json['data']['serviceRequestId']
print(unlock_json)
#lock doors
lockUrl='https://www.mysubaru.com/service/g2/lock/execute.json'
ts = str(int(datetime.datetime.now().timestamp()))
data={'now':ts,'pin':pin,'horn':'true'}
lock=s.post(lockUrl,data=data)
lock.json()
lock_json=lock.json()
lock_request_id=lock_json['data']['serviceRequestId']
statusUrl='https://www.mysubaru.com/service/g2/remoteService/status.json'
while lock_json['data']['success'] is not True:
lockStatus=s.post(statusUrl,data={'serviceRequestId':lock_request_id})
lock_json=lockStatus.json()
lock_request_id=lock_json['data']['serviceRequestId']
print(lock_json)
#remote start engine
engineStartUrl='https://www.mysubaru.com/service/g2/engineStart/execute.json'
ts = str(int(datetime.datetime.now().timestamp()))
remoteStartSettingsUrl='https://www.mysubaru.com/service/g2/remoteStart/fetch.json'
remoteStartSettingsR=s.get(remoteStartSettingsUrl)
data=json.loads(remoteStartSettingsR.json()['data'])
data['now']=ts
data['pin']=pin
data['delay']='0'
data['horn']='true'
start=s.post(engineStartUrl,data=data)
start.json()
start_json=start.json()
start_request_id=lock_json['data']['serviceRequestId']
statusUrl='https://www.mysubaru.com/service/g2/remoteService/status.json'
while start_json['data']['success'] is not True:
startStatus=s.post(statusUrl,data={'serviceRequestId':start_request_id})
start_json=startStatus.json()
start_request_id=start_json['data']['serviceRequestId']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment