My first python project, converting speedy.js (JavaScript speedy bandwidth usage checking) into python script. Thanks to this project, I’ve learned little knowledge about some python library like: urllib, urllib2, cookielib, and regular expression.


import urllib2, urllib, cookielib, re

username = ""
password = "XXXXXXXXXX"

    postdata = urllib.urlencode({
        "username": username, 
        "password": password,
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    r ="", postdata)
    if r:
        r2 ="")
        if r2:
            content =
            content = re.sub(r"[rn]", "", content)
            p = re.compile(r'<b>Pemakaian Speedy</b>(.*?)</TD>.*?' + 
                '<td[^>]*>Pemakaian</td><td[^>]*>(.*?)</td>.*?' + 
                '<td[^>]*>Pemakaian</td><td[^>]*>(.*?)</td>.*?' + 
            result = p.findall(content)
            if result:
                (bulan, persen, pemakaian, bandwidth, kelebihan) = result[0]
                bulan = bulan.replace("&nbsp;", "")
                bulan = re.sub("<.*?>", "", bulan)
                s = "Pemakain Speedy %snn" + 
                    "Terpakai: %sn" + 
                    "Pemakaian: %sn" + 
                    "Limit: %sn" + 
                    "Kelebihan: %sn" % (bulan, persen, pemakaian, bandwidth, kelebihan)
                print s
                raw_input("press return...")
except Exception, why:
    print "Error: %s" % why

Copy and save as file If you’re running on Ubuntu or Gentoo, I’m sure you have python installed.