Sunday, September 5th, 2010

Weather Script v.2
Root page of JMan's Bedpan
A short little bio of JMan and JMan's Bedpan
Some PHP scripts that JMan has written, for public use. MSN Emoticons, Weather, Webcam, Latest Version, Cache, HotScripts
Other random stuff that doesnt belong on any other page. Family Feud Cheat, I *Heart* James, Stupidest Famous Last Words, Funny Search Engine Queries, Funny Euphemisms
Rants by Blakey
A bunch of useful links
. : : Local Weather Forecast

Use it? Show me.


Version II. This magnificent piece of code leeches weather information off of Environment Canada's weather pages, and displays it in a very flexible format on your own website.

   Major updates from the initial version include:
   · English or French Selection
   · MySQL or Flat-File Caching
   · Object Oriented Style
   · Superior Configuration and Customization Capabilites
   · Ability to Show Longer Text Descriptions, and Current Information (if available)
   · Selectable Display Formats Pre-Programmed in
   · POP% Displayed Graphically on the Weather Icons
   · Better Written Code


Explanations:

#.gif - All the different weather image files.
index.php - A redirecting index page to prevent directory viewing.
cache.class.php - Caches fetched information, for quicker results, and less drag on the source.
gpl.txt - A copy of the General Public License.
readme.txt - A quick readme file.
SQL.sql - The SQL table.
testWeather.php - A working example of the script.
weather.class.php - The script page. Include it in the page you want the weather displayed on, then call its functions.


EXAMPLE: (May not be exactly as shown.)

<?
include_once("weather.class.php");

$weather = new getWeather();
$weather->dbUser="root";
$weather->dbPass="";
$weather->dbName="db_name";
$weather->cityCode="on-82";
echo 
"<table cellspacing=1 cellpadding=1>";
if (
$weather->fetchData()){
    echo 
    
"<tr><td colspan=3 align=center>\n\n".$weather->showWeather().
    
"\n</td></tr>";
}
$weather->cityCode="bc-74";
$weather->dispFormat=1;
if (
$weather->fetchData()){
    echo 
"<tr valign=top><td>\n\n".$weather->showWeather()."\n</td>";
}
$weather->cityCode="nf-24";
$weather->dispFormat=2;
$weather->longText=true;
if (
$weather->fetchData()){
    echo 
"<td>\n\n".$weather->showWeather()."\n</td>";
}
$weather->cityCode="nu-21";
if (
$weather->fetchData()){
    echo 
"<td>\n\n".$weather->showCurrent()."\n</td></tr>\n";
}
echo 
"</table>";
?>

 Kitchener-Waterloo
Wednesday
Wednesday night
Thursday
Friday
Saturday
Sunday
Sunny With Cloudy Periods
Clear
Sunny With Cloudy Periods
Sunny
Sunny
A Mix Of Sun And Cloud
Sunny With Cloudy Periods
Clear
Sunny With Cloudy Periods
Sunny
Sunny
A Mix Of Sun And Cloud
High 25°C
Low 12°C
High 26°C
High 28°C
Low 14°C
High 28°C
Low 16°C
High 26°C
Low 14°C
Last Updated: August 16, 2006 @ 11:00 AM EDT
Vancouver
Wednesday
Sunny With Cloudy Periods
Sunny With Cloudy Periods
High 21°C
Wednesday night
A Few Clouds
A Few Clouds
Low 13°C
Thursday
Sunny
Sunny
High 26°C
Friday
Sunny
Sunny
High 27°C
Low 13°C
Saturday
Sunny
Sunny
High 26°C
Low 13°C
Sunday
Sunny
Sunny
High 25°C
Low 14°C
Last Updated:
August 16, 2006
11:00 AM PDT
St. John's
Wednesday
A Few Showers
A few showers ending late this afternoon then cloudy. Amount 2 to 4 mm. Wind south 30 km/h gusting to 50. High 21. UV index 3 or moderate.
High 21°C
Wednesday night
Chance Of Showers
Cloudy. 40 percent chance of showers this evening. Fog patches developing near midnight. Wind south 30 km/h gusting to 50 becoming southwest 20 this evening. Low 16.
Low 16°C
POP 40%
Thursday
Chance Of Showers
A mix of sun and cloud. 40 percent chance of showers in the evening with the risk of a thundershower. Wind west 20 km/h. High 24.
High 24°C
POP 40%
Friday
Sunny
Sunny. Low 14. High 20.
High 20°C
Low 14°C
Saturday
Sunny
Sunny. Low 14. High 20.
High 20°C
Low 14°C
Sunday
Chance Of Showers
A mix of sun and cloud with 40 percent chance of showers. Low 15. High 21.
High 21°C
Low 15°C
POP 40%
Last Updated:
August 16, 2006 @ 11:00 AM NDT
Current Conditions
Iqaluit Airport
Cloudy
Cloudy
08 /16 /06 1:00 PM EDT
Temperature
6°C
Pressure/ Tendency
99.8 kPa↑
Visibility
13 km
Humidity
97 %
Dewpoint
5°C
Wind
SE 8 km/h
Yesterday
Max Temp.
9.9°C
Min Temp.
3.4°C
Precip Total
2.0 mm
Regional Normals
Max Temp.
10°C
Min Temp.
3°C
Today
Sunrise
4:30
Sunset
20:47
Moonrise
19:43
Moonset
18:10


-- DOWNLOAD: PHP4    PHP5 --
2339 Downloads To Date

HotScripts.com
Rating: 4.54 / 5
Votes: 39
Hits: 4,296

LASTEST UPDATES:
March 11, 2009
Version 2.3.5:
There is a new function, array_snip. It does the legwork for the workaround which deals with the extra Tomorrow Night, or X-Day Night long-text Descriptions.
Now the long descriptions should work, and show the right data for the right days again.


April 10, 2008
Version 2.3.4:
Yeah, I had a typo in the name of the cache class file. Fixed.


April 7, 2008
Version 2.3.3:
Added $fontColour so that you can change the font colour of the displayed weather data, from the web page's default colour, to whatever colour you want.


March 19, 2008
Updated to work with new *slightly* different HTML code. Looks like their doing cross browser compatibility stuff.

Oh yeah. And also now, FLAT FILE caching should be supported. Set $useMySQL to false, and make sure you have a properly permissioned cache directory waiting. This is new to me, so it may be buggy.


February 12, 2008
Another big one. Now, you have the option of displaying your weather in French. A bunch of changes were made to accommodate.
Another major change is the ability to show the POP% on top of the weather icon, instead of as green text.
Fixed error with PHP4 version not having array_diff_key().
Cleaned up the code in some spots, and made some other small changes.


February 4, 2008
Fixed a bug in the date/time. Wasn't being replaced properly. Fixed a bug where the forecast wasn't detected properly, resulting in not all days being shown. Added ability to strictly return false on a failed fetchData, so that you could program in your own custom error message, instead of showing the cached data.
Added invisible html comments to give credit where credit is due, yet does not affect appeareance whatsoever. eg:
<!--
Weather Information Collected by Environment Canada [www.weatheroffice.gc.ca]
Displayed via Bedpan.ca's PHP Weather Script [www.bedpan.ca/weather2.php]
-->
Please do not alter this.


January 29, 2008
More small updates. Added "title" strings to the weather images, so they now show descriptions when you hover your mouse over them, also added a variable to set the background colour of the tables. Default is white. Fixed so that the proper Issued/Updated time is displayed for each chunk. Fixed so that file_get_contents() should now suppress displaying errors.

January 28, 2008
Minor update to fix "Not observed" image from showing an invalid image. Now shows the N.A. image. Also a fix so that fetchData() properly returns false on a false. Hopefully.

January 27, 2008
Alright. I'm not going to lie. That was a doozy. Their format change on Jan 25th, 2008 totally changed everything. Lots of rewriting was needed. Should be working now though, yet it was not extensively tested, so there may still be bugs. Email/Comment with any problems you may encounter, being as specific as you can, including city codes and any other useful information.

Updated regular expressions to match current layout, updated all images to current images, added new things to go about the current conditions differently than before, cleaned up a couple things, and messed around with others. A rush job, but it should work.


June 16, 2007
Updated weather.class.php to work with Environment Canada's new format for displaying the weather, date and time. Sorry about the lack of updates.

December 14, 2006
Updated weather.class.php to work with Environment Canada's new format for displaying the date and time.

October 20, 2006
Updated to all the latest weathericons.

September 12, 2006
Added the option to use cURL instead of file_get_contents().

August 29, 2006
I spelled 'February' wrong. Shuddap.

August 18, 2006
Added PHP4 compatable version of weather script for download (the only differences are with the declarations of variables and functions).

August 17, 2006
Fixed issue with mysqlConnect() function, so now it caches.

August 16, 2006
Inital release of v.2 Script.

[Show All 40 Comments]

D
12/23/2009 04:23 PM
Does this PHP used the public weather pages or the XML library they offer: http://dd.weatheroffice.ec.gc.ca/
JMan: It does not make use of the XML pages. From what I remember, when I was looking at the XML, it would have been a little bit less of a file to download, but there wasn't any information about the relevant weather icons, so I didn't bother with it.

Bill
03/12/2009 12:14 PM
An idea to improve the readability.

Start on a new line when appending Tonight: text.
Maybe bold Tonight:

Any thoughts.

Bill
03/12/2009 11:08 AM
Version 2.3.5 has fixed the Tonight problem. The Wiarton ON. forecast is now displaying correctly.

Thanks for all your work.

jared
03/11/2009 11:57 PM
Thanks - looks good :)

jared
03/11/2009 01:14 AM
Happening right now again ;)

Seems if there is like Today / Tonight & then the days, or Today Wednesday / Wednesday night it gets mixed up

kjh.ca/iphone-1.png
kjh.ca/iphone-2.png

as well as
kjh.ca/ff-1.png
kjh.ca/ff-2.png
JMan: Okay. I think I've done a workaround. And in my brief testing, it seems to work fine. It checks if there is a X-night, and if there is, it appends that text do the day portion. This way you don't need another block, but you still get the text.

Also, I noticed that I started working on a version with capabilities for an external CSS... But I never finished it, and it was lost on the back burner. If I have time, I'll try and get that finished too.

Either way, let me know how things work.

[Show All 40 Comments]

Add a Comment (Max: 1 Per Hour)

Please make sure that your comment pertains to this page. If it has nothing to do with this page, I'll just delete it. If you want, you can send me an email here: jman@bedpan.ca.

Name :
Email or URL :
Verification :
All fields are required for submission. Entries with blank fields will not be posted.

disclaimer:
the comments posted throughout my site are submitted by other users.
the things said are not endorsed by me, and do not represent my opinion.