Mercurial > ~darius > hgwebdir.cgi > adslstats
comparison adslstats.py @ 24:806b1ed7f1b5
Get units right for speeds.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sat, 17 Jun 2017 16:52:20 +0930 |
parents | 4b6c811e77df |
children | 7571c101a4ee |
comparison
equal
deleted
inserted
replaced
23:4b6c811e77df | 24:806b1ed7f1b5 |
---|---|
153 bs = bs4.BeautifulSoup(r) | 153 bs = bs4.BeautifulSoup(r) |
154 if bs.find('div', 'login') != None: | 154 if bs.find('div', 'login') != None: |
155 return False | 155 return False |
156 | 156 |
157 # Helper function to extract data | 157 # Helper function to extract data |
158 def getvals(bs, text): | 158 def getvals(bs, text, mult = 1): |
159 subs = bs.findAll('label', text = text)[0].fetchNextSiblings()[0].strings | 159 subs = bs.findAll('label', text = text)[0].fetchNextSiblings()[0].strings |
160 return map(lambda s: float(s.split()[0]), subs) | 160 tmp = map(lambda s: float(s.split()[0]), subs) |
161 return map(lambda s: s * mult, tmp) | |
161 | 162 |
162 if map(None, bs.findAll('label', text = 'DSL Status')[0].fetchNextSiblings()[0].strings)[0] == 'Up': | 163 if map(None, bs.findAll('label', text = 'DSL Status')[0].fetchNextSiblings()[0].strings)[0] == 'Up': |
163 stats.linkup = True | 164 stats.linkup = True |
164 else: | 165 else: |
165 stats.linkup = False | 166 stats.linkup = False |
166 | 167 |
167 stats.upstreammax, stats.downstreammax = getvals(bs, 'Maximum Line rate') | 168 stats.upstreammax, stats.downstreammax = getvals(bs, 'Maximum Line rate', 1e3) |
168 stats.upstream, stats.downstream = getvals(bs, 'Line Rate') | 169 stats.upstream, stats.downstream = getvals(bs, 'Line Rate', 1e3) |
169 stats.uppower, stats.downpower = getvals(bs, 'Output Power') | 170 stats.uppower, stats.downpower = getvals(bs, 'Output Power') |
170 stats.nmup, stats.nmdown = getvals(bs, 'Noise Margin') | 171 stats.nmup, stats.nmdown = getvals(bs, 'Noise Margin') |
171 | 172 |
172 # Line attenuation returns several values for each direction, parse specially and just take the first one | 173 # Line attenuation returns several values for each direction, parse specially and just take the first one |
173 upattens, downattens = map(None, bs.findAll('label', text = 'Line Attenuation')[0].fetchNextSiblings()[0].strings) | 174 upattens, downattens = map(None, bs.findAll('label', text = 'Line Attenuation')[0].fetchNextSiblings()[0].strings) |