I’ve been continuing my journey into Python by modifying my earlier location script to now post details to my website when run.
I’m using the standard urllib
now and moving to slightly more advanced Python language features such as dictionaries (basically the equivalent of a Perl hash).
The code gets the location, calls a CGI script on my website and prints the returned message from that script to the console.
Here’s the code…
# we need access to the location and urllib modules so have to
#import them.
import location
import urllib
# get the mmc, mnc, lac and cellid by calling the gsm_location
# method from the location module.
(mmc, mnc, lac, cellid) = location.gsm_location()
# add the location to a python dictionary called params.
params = urllib.urlencode({'mmc': mmc, 'mnc': mnc, 'lac': lac, 'cellid': cellid})
# open a filehandle to a cgi tracking script that takes
# the contents of dictionary params as parameters.
f = urllib.urlopen("http://www.robertprice.co.uk/cgi-bin/test/cellid.pl?%s" % params)
# get the results, hopefully a message saying OK.
print f.read()
All the CGI script on my website does is to record the parameters passed to it and return a simple text string saying it ran OK.
As you can see it’s really simple to Series 60 Python to communicate over the phone’s network connection. I have to say, this language is turning out to be better than I had expected, and far easier than J2ME.