Ok. I have most of it done..
The problem is Wind Speeds. I don't know where the heck it's getting the wind speeds, but they are not correct. Sometimes they are WAY off.
How do you dump the variables to the screen?
AccuWeather script & templates
Moderators: Developers, Moderators
-
- Posts: 7
- Joined: Fri Jan 16, 2009 3:52 pm
Re: AccuWeather script & templates
I did some reworking of the accuweather.php script. Okay, I rewrote it. For folks in the USA, one can simply change the zip code in the URL to your location. If you prefer metric instead of English measurements, change the metric=0 to metric=1 in the URL.
Hope this helps!
Hope this helps!
Code: Select all
<?php
$file = "http://forecastfox.accuweather.com/adcbin/forecastfox/weather_data.asp?location=20001&metric=0&partner=forecastfox";
$uvindex = array( "Low" => 2, "Moderate" => 4, "High" => 6.5, "Very High" => 9, "Extreme" => 11 );
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "cData");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);
// Dump the output
//print_r($xml->currentconditions);
$pressure = $xml->currentconditions->pressure;
$temperature = $xml->currentconditions->temperature;
$realfeel = $xml->currentconditions->realfeel;
$humidity = rtrim($xml->currentconditions->humidity, '%');
$weathericon = $xml->currentconditions->weathericon;
$windgusts = $xml->currentconditions->windgusts;
$windspeed = $xml->currentconditions->windspeed;
$visibility = $xml->currentconditions->visibility;
$precip = $xml->currentconditions->precip;
$uvi = $uvindex[trim($xml->currentconditions->uvindex)];
echo "weathericon:".$weathericon." temperature:".$temperature." humidity:".$humidity." windgusts:".$windgusts." windspeed:".$windspeed." visibility:".$visibility." realfeel:".$realfeel." precip:".$precip." uvindex:".$uvi." pressure:".$pressure;
?>
Re: AccuWeather script & templates
Hello everybody!
I wonder what i have to do to extract from XML the dorescast (<day number="1"></day>, <day number="2"></day>) etc. Any ideea?
Thanks.
I wonder what i have to do to extract from XML the dorescast (<day number="1"></day>, <day number="2"></day>) etc. Any ideea?
Thanks.
Re: AccuWeather script & templates
It is also possible to find location with geo coordinates:
1) lets say: monaco (http://itouchmap.com/latlong.html) -> 43.7 / 7.4
2) in php script from above modify
3) $ php ./accwthr.php
1) lets say: monaco (http://itouchmap.com/latlong.html) -> 43.7 / 7.4
2) in php script from above modify
Code: Select all
<?php
$file = "http://thale.accu-weather.com/widget/thale/weather-data.asp?slat=43.7&slon=7.4&metric=1";
Code: Select all
php ./accwthr.php
weathericon:01 temperature:27 humidity:73 windgusts:9 windspeed:9 visibility:16 realfeel:32 precip:0.0 uvindex:4 pressure:101
- Attachments
-
- monaco.png (143.17 KiB) Viewed 6974 times
Re: AccuWeather script & templates
I used the following website to get my location http://pastebin.com/dbtemx5F to get me http://forecastfox.accuweather.com/adcb ... orecastfox
and used this script to get me the details
and used this script to get me the details
Code: Select all
<?php
$file = "http://forecastfox.accuweather.com/adcbin/forecastfox/weather_data.asp?location=AFR|ZA|SF006|BELFAST&metric=1&partner=forecastfox";
$uvindex = array( "Low" => 2, "Moderate" => 4, "High" => 6.5, "Very High" => 9, "Extreme" => 11 );
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "cData");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);
// Dump the output
//print_r($xml->currentconditions);
$pressure = $xml->currentconditions->pressure;
$temperature = $xml->currentconditions->temperature;
$realfeel = $xml->currentconditions->realfeel;
$humidity = rtrim($xml->currentconditions->humidity, '%');
$weathericon = $xml->currentconditions->weathericon;
$windgusts = $xml->currentconditions->windgusts;
$windspeed = $xml->currentconditions->windspeed;
$visibility = $xml->currentconditions->visibility;
$precip = $xml->currentconditions->precip;
$uvi = $uvindex[trim($xml->currentconditions->uvindex)];
echo "weathericon:".$weathericon." temperature:".$temperature." humidity:".$humidity." windgusts:".$windgusts." windspeed:".$windspeed." visibility:".$visibility." realfeel:".$realfeel." precip:".$precip." uvindex:".$uvi." pressure:".$pressure;
Re: AccuWeather script & templates
This script works great. But for the location, simply using a US ZIP code in the URL (?location=) worked for me. Thanks.
jckruger wrote:I used the following website to get my location http://pastebin.com/dbtemx5F to get me http://forecastfox.accuweather.com/adcb ... orecastfox
and used this script to get me the details
Code: Select all
<?php $file = "http://forecastfox.accuweather.com/adcbin/forecastfox/weather_data.asp?location=AFR|ZA|SF006|BELFAST&metric=1&partner=forecastfox"; $uvindex = array( "Low" => 2, "Moderate" => 4, "High" => 6.5, "Very High" => 9, "Extreme" => 11 ); $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "cData"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $file); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $result = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($result); // Dump the output //print_r($xml->currentconditions); $pressure = $xml->currentconditions->pressure; $temperature = $xml->currentconditions->temperature; $realfeel = $xml->currentconditions->realfeel; $humidity = rtrim($xml->currentconditions->humidity, '%'); $weathericon = $xml->currentconditions->weathericon; $windgusts = $xml->currentconditions->windgusts; $windspeed = $xml->currentconditions->windspeed; $visibility = $xml->currentconditions->visibility; $precip = $xml->currentconditions->precip; $uvi = $uvindex[trim($xml->currentconditions->uvindex)]; echo "weathericon:".$weathericon." temperature:".$temperature." humidity:".$humidity." windgusts:".$windgusts." windspeed:".$windspeed." visibility:".$visibility." realfeel:".$realfeel." precip:".$precip." uvindex:".$uvi." pressure:".$pressure;
Who is online
Users browsing this forum: No registered users and 3 guests