Get Telstra Bigpond Usage from the command line

If you feel the need to get your Telstra Bigpond usage from the command line, say for putting into a round-robin database for drawing pretty graphs, then give this a go:

#!/usr/bin/env python2.7
import requests, sys, re
from bs4 import BeautifulSoup
    
data = {'username': 'steve.smith', 'password': 'somethingsecret!'}
req = requests.post('https://signon.bigpond.com/login', params=data, allow_redirects=False)

if req.status_code == 302:
    cookies = {'BPSESSION': req.cookies['BPSESSION']}
    headers = {'Referer': 'https://signon.bigpond.com/login?goto=https%3A%2F%2Fusagemeter.bigpond.com%3A443%2Fdaily.do'}
    req = requests.get('https://usagemeter.bigpond.com/daily.do', headers=headers, cookies=cookies)
else:
    print "Didn't get redirected? ", req.status_code
    sys.exit()
    
if req.status_code == 200:
    # html.parser is important as it will ensure the document is parsed as
    # html rather than xml
    soup = BeautifulSoup(req.text, 'html.parser')
    usage = int(soup.find(class_='trStyleTotal').find('b').text) / 1e3
    limit = soup.find('th', text="Monthly allowance").parent.td.text.strip('\r\n\t')
    limit = re.match('\d+', limit).group()
    print usage, "/", limit, "GB"
else:
    print "Couldn't get usage page ", req.status_code
    sys.exit()

Grab it from GitHub

Output

 troy@skade:~$ python bigpond.py
 195.525 / 500 GB