Skip to content

Commit

Permalink
Merge pull request #2 from aa755/gmaps
Browse files Browse the repository at this point in the history
tracking accuracy, logging from a dummy account.
icovada authored Nov 2, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents bb2062e + 5b38d5c commit 6920bb9
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions homeassistant/components/device_tracker/gplus.py
Original file line number Diff line number Diff line change
@@ -24,36 +24,32 @@
CONF_HSID = 'cookie_hsid'
CONF_FREQ = 'data_freq'
CONF_AT = 'data_at'
CONF_ACCURACY = 'accuracy'
CONF_HOST = 'header_host'
#CONF_ACCURACY = 'accuracy'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_ID): vol.Coerce(str),
vol.Required(CONF_URL): vol.Coerce(str),
vol.Optional(CONF_ACCURACY, default=100): vol.Coerce(int),
vol.Required(CONF_SID): vol.Coerce(str),
vol.Required(CONF_SSID): vol.Coerce(str),
vol.Required(CONF_HSID): vol.Coerce(str),
vol.Required(CONF_FREQ): vol.Coerce(str),
vol.Required(CONF_AT): vol.Coerce(str),
vol.Optional(CONF_HOST, default='plus.google.com'): vol.Coerce(str),
# vol.Optional(CONF_ACCURACY, default=100): vol.Coerce(int),
vol.Optional(CONF_INTERVAL, default=1): vol.All(vol.Coerce(int),
vol.Range(min=1)),
vol.Optional(CONF_SCAN_INTERVAL, default=100): vol.Coerce(int)
vol.Optional(CONF_SCAN_INTERVAL, default=10): vol.All(vol.Coerce(int),
vol.Range(min=1, max=59)),
})


def setup_scanner(hass, config, see):
"""Define constants."""
import requests
import re

headers = {
'Host': 'aboutme.google.com',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'X-Same-Domain': '1',
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
'Referer': 'https://aboutme.google.com/',
'DNT': '1',
'Connection': 'keep-alive',
}

max_accuracy = config[CONF_ACCURACY]
# max_accuracy = config[CONF_ACCURACY]
id = config[CONF_ID]
url = config[CONF_URL]
cookie_sid = config[CONF_SID]
@@ -62,7 +58,18 @@ def setup_scanner(hass, config, see):
data_freq = config[CONF_FREQ]
data_at = config[CONF_AT]
url = config[CONF_URL]
regex_float = '-?\d+\.\d+'
host = config[CONF_HOST]

headers = {
'Host': host,
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
'Referer': 'https://' + host + '/',
'X-Same-Domain': '1',
'Connection': 'keep-alive',
}

cookies = {
'SID': cookie_sid,
@@ -80,15 +87,20 @@ def get_position(now):
api_request = requests.post(url, headers=headers, cookies=cookies,
data=data)
if api_request.ok:
location = re.findall(regex_float, api_request.text)

latitude = location[0]
longitude = location[1]
ans = api_request.text
matched_lines = [line for line in ans.split(
'\n') if "www.google.com/maps/" in line]
line = matched_lines[0]
words = line.split(',')
latitude = words[12]
longitude = words[13]
accuracy = words[15]
#_LOGGER.info(api_request.text)

see(
dev_id=id,
gps=(latitude, longitude),
gps_accuracy=max_accuracy,
gps_accuracy=int(accuracy),
)

hass.bus.listen_once(EVENT_HOMEASSISTANT_START, get_position)

0 comments on commit 6920bb9

Please sign in to comment.