Wrote this a couple weeks ago and figured some here might be interested. It's a Python script that connects to the Telecom broadband usage meter website and reads your current usage. I've tested it on a few accounts and it's worked fine on them all.
(If the forum messes up the formatting heres the link: http://tom.henderson.net.nz/post/454031326/check-xtra-broadband-usage-using-python)
Hope someone finds it useful.
[code]
#!/usr/local/bin/python
import sys, re
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
# Optional: uncomment and hard code your account details here:
#myUsername = ''
#myPassword = ''
if len(sys.argv) == 3:
username, password = sys.argv[1:]
else:
try:
username, password = myUsername, myPassword
except:
print "usage: %s username password" % sys.argv[0]
sys.exit(1)
# Browser
br = Browser()
# Load the login page:
url = 'http://www.telecom.co.nz/broadband/usage' # 26.07kb
br.open(url)
# Select the first form:
br.select_form(nr=2)
# Fill in and submit:
br.form['USER'] = username
br.form['PASSWORD'] = password
br.submit()
# Navigate to the 'Current Usage Details' page:
req = br.click_link(text='Current Usage Details')
br.open(req)
html = br.response().read()
# Load html into BeautifulSoup.
# We need to adjust the line that contains ""
# as it confuses the html interpreter.
myMassage = [(re.compile(""), lambda match: '')]
soup = BeautifulSoup(html, markupMassage=myMassage)
# Extract some data and print:
account = soup.findAll('span')[2].string
if len(account.split(' ')[2]) != 8:
print 'Sorry, the account must be a landline.'
else:
print ' Usage for:', account
print 'Current usage plan:', soup.findAll('table')[3].findAll('td')[9].string.strip()
print ' ', soup.findAll('table')[3].findAll('td')[7].string
print ''
data = soup.findAll('table')[9].findAll('td')
print ' Total Downloads:', data[1].string
print ' Total Uploads:', data[3].string
print ' Total Usage:', data[5].string
[/code]