Help with regular expressions

dmbkiwi dmbkiwi at
Tue Aug 26 09:51:31 CEST 2003

I have a problem.  I have written a python based theme for a linux app
called superkaramba, which is effectively an engine for desktop applets
that utilises python as its theming language.  The script basically parses
weather websites, and displays the info in a visually appealing way.

A couple of other people have contributed code to this project,
particularly relating to the parsing of the websites.  Unfortunately, it
is not parsing one particular part of the website properly.  This is
because it is expecting the data to be in a certain form, and occasionally
it is in a different form.  Unfortunately this causes the entire script to
fail to run.

Unfortunately, I know very little about regular expressions and can't get
hold of the person who wrote this part of the script. The other issue I am
struggling with is that there are no error messages as to what's going
wrong, which makes it more difficult to code round the issue.

The issue comes down to a couple of lines in the html for the web page. 
The following lines parse correctly:

 <TD ALIGN=LEFT VALIGN=TOP CLASS=obsInfo2>From the Northeast at 6 mph</TD>

these don't:


the relevant portion of the python script is as follows:

print '==================================================='
p_current = r'''(?isx) # Ignore case, Dot matches all, Verbose
wxicons/52/(?P<icon>\d*?)\.gif # Icon
.*?obsTempTextA>(?P<temp>\d*?)° # Temp
.*?obsTextA>(?P<sky>.*?)</b> # Sky
.*?Feels\sLike<br>(?P<heat>.*?)° # Heat

match =, data1)
if match:
	now.temperature('temp'), 'F')
	now.relative_heat('heat'), 'F')'sky'))
	now.dewpoint('dew'), 'F')
	now.pressure('baro'), 'inHg')
	mywind ='wind')
	now.wind(mywind.replace('From the ', ''))
	now.wind_speed('speed'), 'mph')

Obviously the issue is that the regular expression expects "at", and in
the second line of the html that doesn't parse, there is no at.

The question I have, is how do I go about fixing this.  What I want is to
test to see if the line does or doesn't contain an "at", and if not,
change it to contain an "at".  I'm just not sure how to code the RE in
python to do this. 

Any help would be appreciated.


More information about the Python-list mailing list