Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




26 posts

Geek


# 58728 17-Mar-2010 23:07
Send private message

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]

Create new topic
78 posts

Master Geek


  # 308556 17-Mar-2010 23:37
Send private message

Thanks! I might try to adapt it for another ISP or two. :)



26 posts

Geek


  # 308564 17-Mar-2010 23:56
Send private message

I should have mentioned that you'll need to install mechanize and BeautifulSoup for this script to work. Mechanize handles the browser object (links / forms / cookies etc), and BeautifulSoup makes it easy to parse the html and pull out the data.

Charles, it should be easy enough to modify for other ISPs, as long as they use html and not flash / java etc. Post back if you get anything working.

 
 
 
 


4352 posts

Uber Geek

Moderator
Trusted
Lifetime subscriber

  # 308575 18-Mar-2010 06:10
Send private message

So what does this give you, that TUC doesnt?



26 posts

Geek


  # 308644 18-Mar-2010 10:25
Send private message

What do you mean by TUC?

All this does is let you get your usage from a command line. At work I have to keep an eye on all our broadband plans so I have a script that goes through them one by one and spits out the current usage. Makes it easy to keep an eye on them.

25 posts

Geek


  # 308648 18-Mar-2010 10:38
Send private message

Lovely, thanks Tom.

A real pity XTRA don't have an API that you can adopt to make things easier.

4352 posts

Uber Geek

Moderator
Trusted
Lifetime subscriber

  # 308668 18-Mar-2010 11:02
Send private message

tomhenderson: What do you mean by TUC?

All this does is let you get your usage from a command line. At work I have to keep an eye on all our broadband plans so I have a script that goes through them one by one and spits out the current usage. Makes it easy to keep an eye on them.


TUC, is traffic usage checker. Handy little app that sits in your taskbar. www.tuc.co.nz



26 posts

Geek


  # 308681 18-Mar-2010 11:28
Send private message

Thats a neat little app. My machine is a mac so not an option for me though. I do use a 'Consume' which is a great iPhone app which works with xtra. You can load in all your accounts and it shows them all as progress bars.

 
 
 
 


2136 posts

Uber Geek

Trusted

  # 309205 19-Mar-2010 16:23
Send private message

rscole86: So what does this give you, that TUC doesnt?


Access to the figures from a unix shell prompt? Thus making it scriptable?

Not really interesting for most people, but I think it's quite neat. Now, make it work with TCL please ;)

Tim



26 posts

Geek


  # 429270 20-Jan-2011 17:37
Send private message

Updated this recently when telecom changed their system slightly. This version now cycles through every line listed on your account, doesn't break if you have a mobile plan listed, and prints usage from previous months.

Edit: Sorry guys, this forum won't seem to let me paste code with the formatting correct (no idea how I did it last time). Since this is python it won't run if the indentation is incorrect. The script at the link in my original post is updated to what I was trying to post here.

Create new topic



Twitter and LinkedIn »



Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Arlo unveils its first video doorbell
Posted 21-Oct-2019 08:27


New Zealand students shortlisted for James Dyson Award
Posted 21-Oct-2019 08:18


Norton LifeLock Launches Norton 360
Posted 21-Oct-2019 08:11


Microsoft New Zealand Partner Awards results
Posted 18-Oct-2019 10:18


Logitech introduces new Made for Google keyboard and mouse devices
Posted 16-Oct-2019 13:36


MATTR launches to accelerate decentralised identity
Posted 16-Oct-2019 10:28


Vodafone X-Squad powers up for customers
Posted 16-Oct-2019 08:15


D Link ANZ launches EXO Smart Mesh Wi Fi Routers with McAfee protection
Posted 15-Oct-2019 11:31


Major Japanese retailer partners with smart New Zealand technology IMAGR
Posted 14-Oct-2019 10:29


Ola pioneers one-time passcode feature to fight rideshare fraud
Posted 14-Oct-2019 10:24


Spark Sport new home of NZC matches from 2020
Posted 10-Oct-2019 09:59


Meet Nola, Noel Leeming's new digital employee
Posted 4-Oct-2019 08:07


Registrations for Sprout Accelerator open for 2020 season
Posted 4-Oct-2019 08:02


Teletrac Navman welcomes AI tech leader Jens Meggers as new President
Posted 4-Oct-2019 07:41


Vodafone makes voice of 4G (VoLTE) official
Posted 4-Oct-2019 07:36



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.


Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.