Trivial Thoughts
Thoughts and discussion on programming projects using the Python language.


Python Sites of Note
Software Development



Recent Posts
 6/15/03
 6/2/03
 5/28/03


Subscribe to "Trivial Thoughts" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
 

 

Friday, May 23, 2003
 

Quest for Massage, Part 2

Time to roll up our sleeves...

The first thing I want to do is read in the web page holding the masseuse's appointment schedule.  Easy to do with Python's 'batteries included' standard library.  There is both the 'urllib' and 'urllib2' modules, both of which include a 'urlopen' method.  Here, I'm using 'urllib2':

from urllib2 import urlopen
urlObj = urlopen('www.iwannamassage.com')

This gives me a file-like object I can use do get the web page data (there's no way I'm gonna give you the real URL of the massage schedule page... I'd never get an appointment if I did).  Next, I'll read in all of the data using the 'readlines' method:

data = urlObj.readlines()

Logically, the next thing I want to do is parse the web page data.  Recently, I've been doing a lot of XML parsing for work-related Python projects.  Initially, I used the low-level XML 'expat' parser available in the module 'xml.parsers.expat'.  But recently, I've been using the excellent 'ElementTree' lightweight DOM-like parser by the effbot.

ElementTree is DOM-like in that it parses XML into a tree of elements (hence the name).  Getting the data in a tree makes getting access to any part of the data quite easy. But rather than attempting to do this just like DOM, ElementTree does it in a more pythonic way; for example, you can use a Python iterator to iterate over the sub-elements of any element in the tree.  Go Pythonic!

Since it has become my XML parser of choice, I was happy to discover that ElementTree can be told to use an HTML parser rather than the default XML one.

Hmmm... Getting pretty late.  More in Part 3.


11:34:59 PM  comment []    

Trivial Thoughts...

This is the kick-off post for this, my first weblog attempt.  Herein you will find assorted sharing and discussion on projects covering various topics of interest to me, mostly having to do with the Python programming language.

Quest for Massage, Part 1

This may sound silly, but...

The company I work for (a national-level specialty software developer) made arrangements with a professional masseuse to give in-house massages to our employees.  Nice.  Really nice, after spending all day in front of a keyboard.  You just access her web page, and through that, you can make an appointment for a 15-minute massage up to two weeks in advance.

The Problem: These massage appointments are in great demand.  As our company has grown, the competition for a slot has become fierce.  Early every Monday, the appointment slots for the following week become available on her web page.  By 9:00 AM, they are all taken.  :-(

My Solution: Write a robot.  This robot will be run via cron on a linux box early every Monday morning.  It's job is to make me a massage appointment before all the slots are taken.

Stay tuned as I develop this app using Python and the exellent web interfaces it has to offer...

 


3:07:47 PM  comment []    


Click here to visit the Radio UserLand website. © Copyright 2003 Michael Kent.
Last update: 6/16/2003; 9:23:40 PM.
This theme is based on the SoundWaves (blue) Manila theme.
May 2003
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Apr   Jun

Previous/Next