diff adslstats.py @ 2:b1048f889ef8

Newer Billion modem
author Daniel O'Connor <darius@dons.net.au>
date Wed, 20 Nov 2013 23:55:38 +1030
parents 98fe11ea4c82
children 3748cec0e322
line wrap: on
line diff
--- a/adslstats.py	Sat Mar 28 17:53:25 2009 +1030
+++ b/adslstats.py	Wed Nov 20 23:55:38 2013 +1030
@@ -57,20 +57,10 @@
 
 (options, args) = opts.parse_args()
 
-statsurl = "http://%s/adsl.asp" % (options.name)
+statsurl = "http://%s/status/status_deviceinfo.htm" % (options.name)
 rrdname = "%s.rrd" % (options.base)
 graphbasename = options.base
 
-matchnum = re.compile('([0-9]+(\.[0-9]+)?)')
-statsdict = {
-    7  : 'Upstream',
-    8  : 'Downstream',
-    9  : 'Noise Margin (Upstream)',
-    10 : 'Noise Margin (Downstream)',
-    11 : 'Attenuation (Upstream)',
-    12 : 'Attenuation (Downstream)' }
-
-
 class ADSLStats(object):
     def __str__(self):
         return """Line Rate - Up: %d kbits, Down %d kbits
@@ -79,28 +69,29 @@
                                               self.nmup, self.nmdown,
                                               self.attenup, self.attendown)
 
-def cleannum(s):
-    s1 = matchnum.match(s).groups()[0]
-    try:
-        return int(s1)
-    except ValueError:
-        return float(s1)
-    
 def getstats(f):
     s = BeautifulSoup(f)
-    a = s.findAll('tr')
+    a = s.findAll('td')
     
-    for i in statsdict:
-        assert a[i].td.contents[0].contents[0] == statsdict[i]
+    # Sanity check in case the firmware changes page layout
+    assert(a[122]('font')[0].contents[0] == 'SNR Margin')
+    assert(a[129]('font')[0].contents[0] == 'Line Attenuation')
+    assert(a[136]('font')[0].contents[0] == 'Data Rate')
+
+    # Check if the modem is offline
+    if a[124].contents[0].strip() == 'N/A':
+	return None
 
     stats = ADSLStats()
-    
-    stats.upstream = cleannum(a[7].td.findNext('td').contents[0].contents[0])   # kbits
-    stats.downstream = cleannum(a[8].td.findNext('td').contents[0].contents[0]) # kbits
-    stats.nmup = cleannum(a[9].td.findNext('td').contents[0].contents[0])       # dB
-    stats.nmdown = cleannum(a[10].td.findNext('td').contents[0].contents[0])    # dB
-    stats.attenup = cleannum(a[11].td.findNext('td').contents[0].contents[0])   # dB
-    stats.attendown = cleannum(a[12].td.findNext('td').contents[0].contents[0]) # dB
+
+    stats.nmdown = float(a[124].contents[0])		# dB
+    stats.nmup = float(a[125].contents[0])		# dB
+
+    stats.attendown = float(a[131].contents[0])		# dB
+    stats.attenup = float(a[132].contents[0])		# dB
+
+    stats.downstream = float(a[138].contents[0])	# kbit/sec
+    stats.upstream = float(a[139].contents[0])		# kbit/sec
 
     return stats