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.


tomhenderson

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
Charles000
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. :)



tomhenderson

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.

rscole86
4973 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?



tomhenderson

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.

PhantomSS
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.

rscole86
4973 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

tomhenderson

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.

 
 
 

Free kids accounts - trade shares and funds (NZ, US) with Sharesies (affiliate link).
muppet
2568 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

tomhenderson

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





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

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



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.