[mythtv] MythWeather Addition

myth-dev at mcspuff.com myth-dev at mcspuff.com
Thu Aug 10 21:08:59 UTC 2006


Hey Everyone,

This is my first foray into the Myth development scene, so please bear with
me if I don't follow historical protocol.

I recently decided to set up a myth-box.  It started when a buddy of mine
needed help getting his box to run properly.  He brought it over and left it
with me for a few days.  After I got Myth 0.19 up and running on it, I
couldn't just let it go.  It was so damned convenient!  So, I got my own.

One thing I didn't like about the MythWeather plug-in was the fact that it
pulled all of its weather forecast info from MSNBC.  I live in Canada, and
the Environment Canada website is far more accurate and updated far more
often than MSNBC.  So, I wrote a PHP script that translates Environment
Canada forecasts into MSNBC's syntax.  I thought I'd post it here to see if
anyone wanted to use it.

Here's a brief synopsis on how it works and how to install it:

TO INSTALL
----------

1) Copy 'accid.txt' and 'envcan_to_msnbc.php' to a directory on your web
server.

2) Change the Weather::GetWeatherData() function code in
mythweather/weather.cpp to have it search using the PHP script if the
queried city is Canadian.  Like so:

----------------------------------------------------------------------
if (locale.left(2) = "CA") {
	weatherDataURL locale;
} else {
	weatherDataURL "http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=" + locale;
}
----------------------------------------------------------------------

3) Voila!  All done.  (Similar changes can be made to the mythweb plug-in to
make its weather forecaster look at the PHP script instead of MSNBC for
Canadian cities.


HOW IT WORKS
------------

The script does a simple lookup using the 'accid.txt' file.  I did a quick
cross-reference between the MSNBC city codes and the Environment Canada city
codes.  For example, Edmonton, AB is 'CAXX0126' to MSNBC and 'ab-50' to
Environment Canada.  The 'accid.txt' list has only about 250 Canadian
cities.  Environment Canada provides forecast info for many, many more.  I
didn't have the time to cross-reference all of them with MSNBC.  You can
easily add your own lines to accid.txt.

Once the script knows the Environment Canada city code, it performs a query
to the website (http://www.weatheroffice.ec.gc.ca/).  It parses the returned
HTML code and pulls out the relevant info.  It then re-composes the data
into MSNBC syntax and spits it out.

The result is timely, accurate forecast info presented in MythWeather or
MythWeb for Canadian cities.


You can try it out using the script I have hosted on my domain.  Try
pointing MythWeather at
http://www.mcspuff.com/weather/envcan_to_msnbc.php?acidÊXX0126 to see a
current forecast for Edmonton, Alberta.

Enjoy!

- Joe
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: accid.txt
Url: http://mythtv.org/pipermail/mythtv-dev/attachments/20060810/222c606b/attachment.txt 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: envcan_to_msnbc.php
Type: application/octet-stream
Size: 9328 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20060810/222c606b/attachment.obj 


More information about the mythtv-dev mailing list