[Tutor] Help with Temperature Program
Lloyd Hugh Allen
lha2@columbia.edu
Mon, 27 May 2002 09:50:51 -0400
Sean 'Shaleh' Perry wrote:
>
> On 27-May-2002 Joe Kessel wrote:
> > Hi Listserve,
> >
> > Im very new to programming and python. I need to write a simple program that
> > extracts the current temperature off weather.com. If anyone is willing to
> > give me some basic instructions, I would appreciate it.
> >
> > Thanks,
> >
> > Joe
>
> perhaps if you asked a specific question we could help you better.
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
You need a few things. First, learn files. Once you know files, you need
to
import urllib
filename =
urllib.urlretrieve("http://www.weather.com/weather/local/XXXXX")
(except that that all goes on the same line--hopefully that won't
autowrap on me) (where XXXXX is your zip code)
filename is a tuple with two components; the 0th is the location of the
file, and the second is a mimetools.Message, which I have no idea how to
use. so you can
thefile = open(filename[0], 'r')
and then
currentline = thefile.readline()
until you see text like "insert current temp" or "insert forecast text"
(look at the raw text file, and you'll understand what I mean) and you
can pluck the relevant information out of those lines. DO NOT expect
your temperature to always be a number; sometimes it will be "N/A".
good luck. Don't know if that was basic; you have a relatively
complicated task for a "first time programming" type thing.