Quest for Massage, Part 8
The latest version of the project shows improvements in two areas. First, I've added in a (rather primative) method for getting my list of appoinment time spans to exclude. Appointment time spans to be excluded are now listed in a file named "conflicts.txt. Each line in the file has the form 'date<comma>start time<comma>end time'. For example: 07/15/2003,12:30,13:30
Times are given in 24-hour military-style time. There can be any number of such lines in the file, which is automatically read upon the robot's startup.
This method of defining appointment exclusion times is a stand-in for what I'll eventually shoot for, which is a way of pulling the scheduling conflicts out of a PIM.
The second area of improvement involves the use of mxDateTime. The slotToDateTime method of the ApptSched class did a lot of work to convert the dates and times given in the web page's appointment schedule table into a form that could be used to instantiate a DateTime object: def slotToDateTime(self, timeIndex, dateIndex): """Given the indexes into a two-dimension array that identifies a slot, this method converts the date and time for that slot into a form that can be used to instantiate an mx.DateTime object, and returns that object.""" timeRaw = self.times[timeIndex] dateRaw = self.dates[dateIndex] dateSplit = dateRaw.split() # The appointment schedule dates have no year info. For now, assume # 2003. year = 2003 month = self.monthNameToNumMap[dateSplit[1][:3].lower()] day = int(dateSplit[2]) timeSplit1 = timeRaw.split() timeSplit2 = timeSplit1[0].split(":") hour = int(timeSplit2[0]) if timeSplit1[1].lower() == "pm": hour += 12 minute = int(timeSplit2[1]) return DateTime.DateTime(year, month, day, hour, minute)
Now, the mxDateTime package comes with a parser which is supposed to be able to take a date and time in the form of a string and return a DateTime object. However, I wasn't able to get it to work properly, and so had to resort to the above extra work. Then I added the new scheduling conflict code, that needs to read in dates and times from a file and create DateTime object. I ran into the same problems with the mxDateTime string parser, and had to investigate it all again. What I found was interesting. It seems that the mxDateTime parser function DateTime.Parser.DateTimeFromString() generates a 'time out of range' error when parsing the time string "12:15 PM". Once I dug into it, I discovered that upon seeing the 'PM', the code adds 12 to the hour to convert into 24-hour format time. This results in an hour of 24, when the legal range is 0-23. Obviously, you should only add 12 hours for hour values of 1 PM and greater. Interestingly, the above code I wrote has the same problem. I was able to fix the mxDateTime code by hacking in a test that enforced that rule. I'll have to follow up on that with M.A. Lemburg.
Once I put in the mxDateTime parser fix, I was able to greatly simplify slotToDateTime() by using the parser rather than all of the code I'd had to write to do the parsing myself. This reduced the method down to: def slotToDateTime(self, timeIndex, dateIndex): """Given the indexes into a two-dimension array that identifies a slot, this method converts the date and time for that slot into a form that can be used to instantiate an mx.DateTime object, and returns that object.""" timeRaw = self.times[timeIndex] dateRaw = self.dates[dateIndex] fullDateTimeString = " ".join([dateRaw.split(",")[1].strip(), currYear, timeRaw]) dateTimeObj = DateTime.Parser.DateTimeFromString(fullDateTimeString) return dateTimeObj
A third area I'd hope to make substantial improvement in has to do with the verision of HTML Tidy I'm using. The effbot announced that an HTML parser for ElementTree using the library-ized version of HTML Tidy was now available. Of course, I downloaded it immediately. Unfortunately, there seems to be a problem with the Windows installer for the package, so I'm unable to try it out as of yet. I'll have to follow up with the effbot on that. Stay tuned...
10:43:40 PM
|
|