Mercurial > code > home > repos > homeauto
comparison service/wifi/scrape_unmaintained.py @ 1226:7de8f0cd3392
very big rewrite. py3; orbi-only for now; n3 config file; delete or move out dead code
Ignore-this: bfecea6f4990d34b36cc6d97cc6c6fa2
darcs-hash:79a3d55bfae5776b2374faa2020b6e27f17eb390
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sat, 30 Mar 2019 23:38:47 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1225:b8c0daabe5a5 | 1226:7de8f0cd3392 |
---|---|
1 | |
2 @inlineCallbacks | |
3 def loadUvaData(): | |
4 import lxml.html.soupparser | |
5 | |
6 config = json.load(open("priv-uva.json")) | |
7 headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]} | |
8 resp = yield fetch('http://10.2.0.2/wlstationlist.cmd', headers=headers) | |
9 root = lxml.html.soupparser.fromstring(resp.body) | |
10 byMac = {} | |
11 for tr in root.cssselect('tr'): | |
12 mac, connected, auth, ssid, iface = [td.text_content().strip() for td in tr.getchildren()] | |
13 if mac == "MAC": | |
14 continue | |
15 connected = connected.lower() == 'yes' | |
16 byMac[mac] = dict(mac=mac, connected=connected, auth=auth == 'Yes', ssid=ssid, iface=iface) | |
17 | |
18 resp = yield fetch('http://10.2.0.2/DHCPTable.asp', headers=headers) | |
19 for row in re.findall(r'new AAA\((.*)\)', resp.body): | |
20 clientHostname, ipaddr, mac, expires, iface = [s.strip("'") for s in row.rsplit(',', 4)] | |
21 if clientHostname == 'wlanadv.none': | |
22 continue | |
23 byMac.setdefault(mac, {}).update(dict( | |
24 clientHostname=clientHostname, connection=iface, ipaddr=ipaddr, dhcpExpires=expires)) | |
25 | |
26 returnValue(sorted(byMac.values())) | |
27 | |
28 @inlineCallbacks | |
29 def loadCiscoData(): | |
30 config = json.load(open("priv-uva.json")) | |
31 headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]} | |
32 print(headers) | |
33 resp = yield fetch('http://10.2.0.2/', headers=headers) | |
34 print(resp.body) | |
35 returnValue([]) | |
36 | |
37 | |
38 def jsValue(js, variableName): | |
39 # using literal_eval instead of json parser to handle the trailing commas | |
40 val = re.search(variableName + r'\s*=\s*(.*?);', js, re.DOTALL).group(1) | |
41 return ast.literal_eval(val) | |
42 | |
43 | |
44 def _parseZyxel(self, data, routerName): | |
45 import lxml.html.soupparser | |
46 | |
47 root = lxml.html.soupparser.fromstring(data) | |
48 for tr in root.cssselect('tr'): | |
49 mac, assoc, uth, ssid, iface = [td.text_content().strip() for td in tr.getchildren()] | |
50 if mac == "MAC": | |
51 continue | |
52 assoc = assoc.lower() == 'yes' | |
53 yield dict(router=routerName, mac=mac, assoc=assoc, connected=assoc) | |
54 | |
55 def _parseTomato(self, data, routerName): | |
56 for iface, mac, signal in jsValue(data, 'wldev'): | |
57 yield dict(router=routerName, mac=mac, signal=signal, connected=bool(signal)) |