Thursday, July 29th, 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 --
2175 Downloads To Date

HotScripts.com
Rating: Not Yet Rated / 5
Votes: 0
Hits: 0

LASTEST 5 UPDATES: [Show All 17 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.

[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.