exutable
September 24th, 2009, 09:31 AM
Hello,
I wrote a python script to pull my telmore usage(danish cellular provider), I was wondering what processes I should use to convert this to Java, for use in an android app. What libraries etc?
Please also comment if I have written something ineffectively, wrong practice etc.
Code is of course released under GPLv2:
import urllib
import urllib2
import sys
import cookielib
import hashlib
from BeautifulSoup import BeautifulSoup
#Accept cookies to browse telmore website
cookieJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(c ookieJar))
#Add headers
opener.addheaders = [('User-agent', "Mozilla/5.0")]
#Accept arguments for username and password
username = sys.argv[1]
password = sys.argv[2]
#Url requests, first page is login, second is a frame of the login page
url = "https://www.telmore.dk/t2/j_security_check"
url2 = "https://www.telmore.dk/t2/mytelmore/index.do"
#Fill the forms with the username and password arguments
form = { "j_username" : username,
"j_password" : password }
#Encode the form and create request
encodedForm = urllib.urlencode(form)
request = urllib2.Request(url, encodedForm)
page = opener.open(request)
#Request the second page
request = urllib2.Request(url2)
page = opener.open(request)
contents = page.read()
#Beatiful soup to parse the html and sort out the span tag with class saldo
soup = BeautifulSoup(contents)
saldospan = soup.findAll('span')
saldo = saldospan[0].contents[0].strip()
print saldo
I wrote a python script to pull my telmore usage(danish cellular provider), I was wondering what processes I should use to convert this to Java, for use in an android app. What libraries etc?
Please also comment if I have written something ineffectively, wrong practice etc.
Code is of course released under GPLv2:
import urllib
import urllib2
import sys
import cookielib
import hashlib
from BeautifulSoup import BeautifulSoup
#Accept cookies to browse telmore website
cookieJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(c ookieJar))
#Add headers
opener.addheaders = [('User-agent', "Mozilla/5.0")]
#Accept arguments for username and password
username = sys.argv[1]
password = sys.argv[2]
#Url requests, first page is login, second is a frame of the login page
url = "https://www.telmore.dk/t2/j_security_check"
url2 = "https://www.telmore.dk/t2/mytelmore/index.do"
#Fill the forms with the username and password arguments
form = { "j_username" : username,
"j_password" : password }
#Encode the form and create request
encodedForm = urllib.urlencode(form)
request = urllib2.Request(url, encodedForm)
page = opener.open(request)
#Request the second page
request = urllib2.Request(url2)
page = opener.open(request)
contents = page.read()
#Beatiful soup to parse the html and sort out the span tag with class saldo
soup = BeautifulSoup(contents)
saldospan = soup.findAll('span')
saldo = saldospan[0].contents[0].strip()
print saldo