comparison adslstats.py @ 36:5dbc310f1eca

Fix uptime parser broken by previous commit. Add comment about it while I'm here.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 17 Nov 2020 15:47:56 +1030
parents b79c03810bbe
children 4f9a79f733ff
comparison
equal deleted inserted replaced
35:815e6b61d76e 36:5dbc310f1eca
198 198
199 # Convert something like '2days 17hours 28min 19sec' into seconds 199 # Convert something like '2days 17hours 28min 19sec' into seconds
200 uptime = re.findall('([0-9]+)', list(bs.findAll('label', text = 'DSL Uptime')[0].fetchNextSiblings()[0].strings)[0]) 200 uptime = re.findall('([0-9]+)', list(bs.findAll('label', text = 'DSL Uptime')[0].fetchNextSiblings()[0].strings)[0])
201 uptime.reverse() # End up with an array of seconds, minutes, hours, etc 201 uptime.reverse() # End up with an array of seconds, minutes, hours, etc
202 mults = [1, 60, 60 * 60, 24 * 60 * 60] 202 mults = [1, 60, 60 * 60, 24 * 60 * 60]
203 if len(uptime) != len(mults): 203 # Basic sanity check of the number of elements, should be at least 1
204 if len(uptime) == 0 or len(uptime) > len(mults):
204 print('Unexpected number of uptime elements (%s)' % str(uptime)) 205 print('Unexpected number of uptime elements (%s)' % str(uptime))
205 stats.uptime = None 206 stats.uptime = None
206 else: 207 else:
207 stats.uptime = reduce(lambda a, b: a + b, [int(a[0]) * a[1] for a in zip(uptime, mults)]) 208 stats.uptime = reduce(lambda a, b: a + b, [int(a[0]) * a[1] for a in zip(uptime, mults)])
208 209