Mercurial > code > home > repos > homeauto
annotate service/tomatoWifi/wifi.py @ 419:fdbdecdecd0b
use rel path for config
Ignore-this: 5f2c4d0f4004f4472f89b6c9478b846d
author | drewp@bigasterisk.com |
---|---|
date | Sat, 30 Mar 2019 16:57:08 -0700 |
parents | f20e66ace980 |
children |
rev | line source |
---|---|
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
1 import re, ast, logging, socket, json |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
2 import lxml.html.soupparser |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
3 from twisted.internet.defer import inlineCallbacks, returnValue |
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
4 from cyclone.httpclient import fetch |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
5 from rdflib import Literal, Graph, RDFS, URIRef |
0 | 6 |
7 log = logging.getLogger() | |
8 | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
9 class Router(object): |
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
10 def __repr__(self): |
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
11 return repr(self.__dict__) |
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
12 |
0 | 13 class Wifi(object): |
14 """ | |
15 gather the users of wifi from the tomato routers | |
16 """ | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
17 def __init__(self, accessN3="/my/proj/openid_proxy/access.n3"): |
272 | 18 self.rereadConfig() |
19 #self._loadRouters(accessN3, tomatoUrl) | |
20 | |
21 def rereadConfig(self): | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
22 self.graph = Graph() |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
23 self.graph.parse('config.n3', format='n3') |
272 | 24 |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
25 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
26 def _loadRouters(self, accessN3, tomatoUrl): |
0 | 27 g = Graph() |
28 g.parse(accessN3, format="n3") | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
29 repl = { |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
30 '/wifiRouter1/' : None, |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
31 #'/tomato2/' : None |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
32 } |
0 | 33 for k in repl: |
34 rows = list(g.query(''' | |
35 PREFIX p: <http://bigasterisk.com/openid_proxy#> | |
36 SELECT ?prefix WHERE { | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
37 ?site |
0 | 38 p:requestPrefix ?public; |
39 p:proxyUrlPrefix ?prefix | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
40 . |
0 | 41 }''', initBindings={"public" : Literal(k)})) |
42 repl[k] = str(rows[0][0]) | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
43 log.debug('repl %r', repl) |
0 | 44 |
45 self.routers = [] | |
46 for url in tomatoUrl: | |
47 name = url | |
48 for k, v in repl.items(): | |
49 url = url.replace(k, v) | |
50 | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
51 r = Router() |
52 | 52 http, tail = url.split('//', 1) |
53 userPass, tail = tail.split("@", 1) | |
54 r.url = http + '//' + tail | |
55 r.headers = {'Authorization': ['Basic %s' % userPass.encode('base64').strip()]} | |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
56 r.name = {'wifiRouter1' : 'bigasterisk5', |
0 | 57 'tomato2' : 'bigasterisk4'}[name.split('/')[1]] |
58 self.routers.append(r) | |
59 | |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
60 @inlineCallbacks |
0 | 61 def getPresentMacAddrs(self): |
272 | 62 self.rereadConfig() |
341
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
63 rows = yield loadOrbiData() |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
64 for row in rows: |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
65 if 'clientHostname' in row: |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
66 row['name'] = row['clientHostname'] |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
67 mac = URIRef('http://bigasterisk.com/mac/%s' % row['mac'].lower()) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
68 label = self.graph.value(mac, RDFS.label) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
69 if label: |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
70 row['name'] = label |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
71 returnValue(rows) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
72 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
73 @inlineCallbacks |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
74 def getPresentMacAddrs_multirouter(self): |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
75 rows = [] |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
76 |
0 | 77 for router in self.routers: |
78 log.debug("GET %s", router) | |
79 try: | |
52 | 80 resp = yield fetch(router.url, headers=router.headers, |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
81 timeout=2) |
0 | 82 except socket.error: |
83 log.warn("get on %s failed" % router) | |
84 continue | |
52 | 85 data = resp.body |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
86 if 'Wireless -- Authenticated Stations' in data: |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
87 # zyxel 'Station Info' page |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
88 rows.extend(self._parseZyxel(data, router.name)) |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
89 else: |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
90 # tomato page |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
91 rows.extend(self._parseTomato(data, router.name)) |
51
d2842eedd56d
rewrite tomatowifi from restkit to cyclone httpclient
drewp@bigasterisk.com
parents:
36
diff
changeset
|
92 |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
93 for r in rows: |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
94 try: |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
95 r['name'] = self.knownMacAddr[r['mac']] |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
96 except KeyError: |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
97 pass |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
98 |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
99 returnValue(rows) |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
100 |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
101 def _parseZyxel(self, data, routerName): |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
102 root = lxml.html.soupparser.fromstring(data) |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
103 for tr in root.cssselect('tr'): |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
104 mac, assoc, uth, ssid, iface = [td.text_content().strip() for td in tr.getchildren()] |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
105 if mac == "MAC": |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
106 continue |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
107 assoc = assoc.lower() == 'yes' |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
108 yield dict(router=routerName, mac=mac, assoc=assoc, connected=assoc) |
0 | 109 |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
110 def _parseTomato(self, data, routerName): |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
111 for iface, mac, signal in jsValue(data, 'wldev'): |
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
112 yield dict(router=routerName, mac=mac, signal=signal, connected=bool(signal)) |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
113 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
114 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
115 @inlineCallbacks |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
116 def loadUvaData(): |
419 | 117 config = json.load(open("priv-uva.json")) |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
118 headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]} |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
119 resp = yield fetch('http://10.2.0.2/wlstationlist.cmd', headers=headers) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
120 root = lxml.html.soupparser.fromstring(resp.body) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
121 byMac = {} |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
122 for tr in root.cssselect('tr'): |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
123 mac, connected, auth, ssid, iface = [td.text_content().strip() for td in tr.getchildren()] |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
124 if mac == "MAC": |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
125 continue |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
126 connected = connected.lower() == 'yes' |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
127 byMac[mac] = dict(mac=mac, connected=connected, auth=auth == 'Yes', ssid=ssid, iface=iface) |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
128 |
175
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
129 resp = yield fetch('http://10.2.0.2/DHCPTable.asp', headers=headers) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
130 for row in re.findall(r'new AAA\((.*)\)', resp.body): |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
131 clientHostname, ipaddr, mac, expires, iface = [s.strip("'") for s in row.rsplit(',', 4)] |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
132 if clientHostname == 'wlanadv.none': |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
133 continue |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
134 byMac.setdefault(mac, {}).update(dict( |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
135 clientHostname=clientHostname, connection=iface, ipaddr=ipaddr, dhcpExpires=expires)) |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
136 |
c81a451f9b26
rewrites for better graph export, removal of dhcp reader
drewp@bigasterisk.com
parents:
62
diff
changeset
|
137 returnValue(sorted(byMac.values())) |
202
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
138 |
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
139 @inlineCallbacks |
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
140 def loadCiscoData(): |
419 | 141 config = json.load(open("priv-uva.json")) |
202
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
142 headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]} |
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
143 print headers |
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
144 resp = yield fetch('http://10.2.0.2/', headers=headers) |
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
145 print resp.body |
7faf642438bc
start of code for reading cisco router data
drewp@bigasterisk.com
parents:
175
diff
changeset
|
146 returnValue([]) |
341
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
147 |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
148 @inlineCallbacks |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
149 def loadOrbiData(): |
419 | 150 config = json.load(open("priv-uva.json")) |
341
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
151 headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]} |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
152 resp = yield fetch('http://orbi.bigasterisk.com/DEV_device_info.htm', headers=headers) |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
153 |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
154 if not resp.body.startswith(('device=', 'device_changed=0\ndevice=', 'device_changed=1\ndevice=')): |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
155 raise ValueError(resp.body) |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
156 |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
157 ret = [] |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
158 for row in json.loads(resp.body.split('device=', 1)[-1]): |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
159 ret.append(dict( |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
160 connected=True, |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
161 ipaddr=row['ip'], |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
162 mac=row['mac'].lower(), |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
163 contype=row['contype'], |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
164 model=row['model'], |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
165 clientHostname=row['name'] if row['name'] != 'Unknown' else None)) |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
166 returnValue(ret) |
f20e66ace980
wifi support for scraping Orbi admin page
drewp@bigasterisk.com
parents:
272
diff
changeset
|
167 |
62
f8cc3d1baa85
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
drewp@bigasterisk.com
parents:
52
diff
changeset
|
168 |
0 | 169 def jsValue(js, variableName): |
170 # using literal_eval instead of json parser to handle the trailing commas | |
171 val = re.search(variableName + r'\s*=\s*(.*?);', js, re.DOTALL).group(1) | |
172 return ast.literal_eval(val) |