[Tutor] Parsing non-uniform strings
Timothy Wilson
wilson@visi.com
Mon, 19 Nov 2001 18:50:25 -0600 (CST)
Hi everyone,
I'm working up an assignment for my programming students and I'd like to get
some feedback on strategies that could be used to solve this problem.
The basic assignment is to retrieve the current weather conditions from the
National Weather Service's automated stations using the urllib2 module and
display them in some human-readable format. The challenge is that that the
codes are not as uniform as I would like.
The data are given in "METAR" format. (See a description and relevant links
at the Web page I'm working on at
http://www.isd197.org/sibley/cs/icp/assignments/weather_html)
Here are five sample METAR reports from a variety of stations including
South St. Paul, Minnesota; Barrow, Alaska; San Diego, California; Denver,
Colorado; and New York, New York.
2001/11/19,23:56:00,KSGS,192356Z,AUTO,00000KT,10SM,CLR,03/M07,A3019,RMK,AO2
2001/11/19,21:53:00,PABR,192153Z,11019KT,4SM,BLSN,BR,FEW012,OVC038,M17/M18,A2985,RMK,AO2,CIG,12,NE,SLP110,T11671178
2001/11/19,19:57:00,KNKX,191957Z,32007KT,15SM,FEW200,22/09,A3013,RMK,SLP199,T02170094
2001/11/19,21:53:00,KDEN,192153Z,13007KT,10SM,FEW250,11/M07,A3032,RMK,AO2,SLP263,T01061067
2001/11/19,21:51:00,KLGA,192151Z,17008KT,10SM,FEW250,13/10,A2996,RMK,AO2,SLP145,T01330100
You can see that there is some uniformity, but not much. At this point I
would like my students to retrieve the date, time, and temperature. (See my
Web page for details about the particular fields.)
Does anyone have some general advise about parsing data like this? This may
be biting off more than my students are able to chew at this point.
-Tim
--
Tim Wilson | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.org | http://www.zope.com
W. St. Paul, MN | | http://slashdot.org
wilson@visi.com | <dtml-var pithy_quote> | http://linux.com