Hardware Reference
In-Depth Information
Like the train times you've just seen, each site presents what it feels is the best tradeoff between information and
clarity. Consequently, some weather reports comprise only one-line daily commentaries, while others have an hourly
breakdown, with temperatures, wind speed, and windchill factors. Pick one with the detail you appreciate and, as
mentioned previously, is available with an API or can easily be scraped.
In this example, I'll use the Yahoo! reports. This is an XML file that changes as often as the weather (literally!) and
can be downloaded according to your region. This can be determined by going through the Yahoo! weather site as
a human and noting the arguments in the URL. For London, this is UKXX0085 , which enables the forecast feed to be
downloaded with this:
#!/bin/bash
LOGFILE=/var/log/minerva/cache/weather.xml
wget -q http://weather.yahooapis.com/forecastrss?p=UKXX0085 -O $LOGFILE
You can then process this with XML using a style sheet and xsltproc :
RESULT_INFO=/var/log/minerva/cache/weather_info.txt
rm $RESULT_INFO
xsltproc /usr/local/minerva/bin/weather/makedata.xsl $LOGFILE > $RESULT_INFO
This converts a typical XML like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss xmlns:yweather=" http://xml.weather.yahoo.com/ns/rss/1.0 "
xmlns:geo=" http://www.w3.org/2003/01/geo/wgs84_pos #" version="2.0">
<channel>
<title>Weather - London, UK</title>
<language>en-us</language>
<yweather:location city="Luton" region="" country="UK"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="26" direction="50" speed="10" />
<yweather:atmosphere humidity="93" visibility="3.73" pressure="30.65" rising="1"/>
<yweather:astronomy sunrise="7:50 am" sunset="4:38 pm"/>
<image>
<title>Weather</title>
<width>142</width>
<height>18</height>
<url> http://todays_weather_chart.gif</url >
</image>
<item>
<yweather:forecast day="Tue" date="26 Jan 2010" low="30" high="36"
text="Mostly Cloudy" code="27" />
<yweather:forecast day="Wed" date="27 Jan 2010" low="26" high="35"
text="Partly Cloudy" code="30" />
<guid isPermaLink="false">UKXX0085_2010_01_26_4_20_GMT</guid>
</item>
</channel>
</rss>
Search WWH ::




Custom Search