AccuWeather script & templates

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

User avatar
Simba7
Posts: 31
Joined: Tue Sep 11, 2007 10:56 am

Post by Simba7 »

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?
JeffRoberson
Posts: 7
Joined: Fri Jan 16, 2009 3:52 pm

Re: AccuWeather script & templates

Post by JeffRoberson »

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!

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;

?>

FireEyes
Posts: 1
Joined: Sun Feb 20, 2011 3:19 am

Re: AccuWeather script & templates

Post by FireEyes »

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.
seco
Posts: 11
Joined: Wed Mar 30, 2011 2:13 am

Re: AccuWeather script & templates

Post by seco »

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

Code: Select all

<?php
$file = "http://thale.accu-weather.com/widget/thale/weather-data.asp?slat=43.7&slon=7.4&metric=1";
3) $ php ./accwthr.php

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
monaco.png (143.17 KiB) Viewed 6973 times
jckruger
Posts: 7
Joined: Wed Jun 17, 2015 6:56 pm

Re: AccuWeather script & templates

Post by jckruger »

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;
kinimod
Posts: 7
Joined: Sat Jul 11, 2015 2:26 pm

Re: AccuWeather script & templates

Post by kinimod »

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;
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests