Here's a simple weather label icon, when clicked it will show current temperature in the user button and will show forecast in the menu (11 days max).Change log:
Jan 26 2014 Fixed decimal separator bug
Nov 2 2013 Added- forecast menu.
I use OpenWeatherMap API now. (as of Nov 1st 2013 google removed it's weather API) ------How it works------------
1) Add a new User Button in the toolbar.
2) In the on-click edit field paste the below code and OK.
3) Click on the button to display current temperature and menu shows the forecast.
-------------------------------
Code: Select all
//Weather and Forecast in your city (using OpenWeatherMap API)
//Simple script that displays current temperature as ctb label and forecast as menu
//Change the location, unit and forecast days in lines 1,2 and 3 respectively.
$location="New york, USA";// Can be of type "City, State, Country" or just "City, Country" or even "City" in most cases
$unit="metric";//Set it to "metric" for celsius, "imperial" for fahrenheit and "" for kelvin
$forecastdays=5;//upto 11 days
IF($forecastdays>11){
$forecastdays=11;
}
$url=readurl("http://api.openweathermap.org/data/2.5/find?q=$location&units=$unit&mode=xml",,,8);
$url2=readurl("http://api.openweathermap.org/data/2.5/forecast/daily?q=$location&mode=xml&units=$unit&cnt=$forecastdays",,,8);
$quote=chr(34);
//City name
$city=gettoken($url, 2, "<city id=");
$city=gettoken($city, 1, "$quote>");
$city=gettoken($city, 2, "name=$quote");
status "$city weather";
//Current Weather
$TempNow=gettoken($url, 2, "<temperature value=$quote");
$TempNow=gettoken($TempNow, 1, "$quote min=");
//IF((get("locale", 14)==",")){
//$TempNow=replace ($TempNow,".", ",");
//}
//ELSE{
//$TempNow=replace ($TempNow,",", ".");
//}
$TempNow=round("$TempNow");
IF($unit LikeI "metric"){
$TempNow=$TempNow."C";
}
ELSEIF($unit LikeI "imperial"){
$TempNow=$TempNow."F";
}
ELSE{
$TempNow=$TempNow."K";
}
ctbicon("label: $TempNow >554433,ffffee");
wait(50);
//Weather Forecast
$daycount=1;
$token=2;
$forecastlist="";
WHILE ($token-2<$forecastdays){
$forecast=gettoken($url2, $token, "<temperature day=$quote");
$forecast=gettoken($forecast, 1, "$quote min=");
//IF((get("locale", 14)==",")){
// $forecast=replace ($forecast,".", ",");
// }
//ELSE{
// $forecast=replace ($forecast,",", ".");
//}
$forecast=round("$forecast");
IF($unit LikeI "metric"){
$forecast=$forecast."C";
}
ELSEIF($unit LikeI "imperial"){
$forecast=$forecast."F";
}
ELSE{
$forecast=$forecast."K";
}
$day=formatdate(,"ddd", "d", $daycount);
$forecast="$forecast [$day]";
$forecastlist="$forecastlist<crlf>$forecast";
$token++;
$daycount++;
}
popupmenu($forecastlist,,,,,,"<crlf>");
Feel free to use it the way you want.