Mercurial > code > home > repos > homeauto
changeset 1146:b62ee2697b8b
wifi support for scraping Orbi admin page
Ignore-this: b49c8e63fb2e0eeb2757958b1c10dcae
darcs-hash:cc321e9add92e4d48a23f576ad8343ec71c15455
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sat, 03 Mar 2018 18:14:08 -0800 |
parents | 0ba7a29a1886 |
children | ef494fe0499f |
files | service/tomatoWifi/wifi.py |
diffstat | 1 files changed, 22 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/service/tomatoWifi/wifi.py Sat Mar 03 18:13:08 2018 -0800 +++ b/service/tomatoWifi/wifi.py Sat Mar 03 18:14:08 2018 -0800 @@ -60,7 +60,7 @@ @inlineCallbacks def getPresentMacAddrs(self): self.rereadConfig() - rows = yield loadUvaData() + rows = yield loadOrbiData() for row in rows: if 'clientHostname' in row: row['name'] = row['clientHostname'] @@ -144,7 +144,27 @@ resp = yield fetch('http://10.2.0.2/', headers=headers) print resp.body returnValue([]) - + +@inlineCallbacks +def loadOrbiData(): + config = json.load(open("/my/proj/homeauto/service/tomatoWifi/priv-uva.json")) + headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]} + resp = yield fetch('http://orbi.bigasterisk.com/DEV_device_info.htm', headers=headers) + + if not resp.body.startswith(('device=', 'device_changed=0\ndevice=', 'device_changed=1\ndevice=')): + raise ValueError(resp.body) + + ret = [] + for row in json.loads(resp.body.split('device=', 1)[-1]): + ret.append(dict( + connected=True, + ipaddr=row['ip'], + mac=row['mac'].lower(), + contype=row['contype'], + model=row['model'], + clientHostname=row['name'] if row['name'] != 'Unknown' else None)) + returnValue(ret) + def jsValue(js, variableName): # using literal_eval instead of json parser to handle the trailing commas