I had found some code on the forum and was able to incorporate in my page http://www.komokaweather.com/weather but today the data is not being shown.
Today it looks like the old API has come to an end for me.
I have been modifying the script for using my new WU API but have not been successful. I am obviously doing something wrong or missing something as the data from the json output is not showing.
My previous working script was
Code: Select all
<?php
$json_string = file_get_contents("http://api.wunderground.com/api/OLD API KEY/conditions/q/pws:IONTARIO226.json");
$parsed_json = json_decode($json_string);
$observation_time = $parsed_json->{'current_observation'}->{'observation_time'};
$weather = $parsed_json->{'current_observation'}->{'weather'};
$temp_c = $parsed_json->{'current_observation'}->{'temp_c'};
$wind_kph = $parsed_json->{'current_observation'}->{'wind_kph'};
$wind_dir = $parsed_json->{'current_observation'}->{'wind_dir'};
$wind_gust_kph = $parsed_json->{'current_observation'}->{'wind_gust_kph'};
$feelslike_c = $parsed_json->{'current_observation'}->{'feelslike_c'};
$heat_index_c = $parsed_json->{'current_observation'}->{'heat_index_c'};
$dewpoint_c = $parsed_json->{'current_observation'}->{'dewpoint_c'};
$windchill_c = $parsed_json->{'current_observation'}->{'windchill_c'};
$pressure_mb = $parsed_json->{'current_observation'}->{'pressure_mb'};
$pressure_trend = $parsed_json->{'current_observation'}->{'pressure_trend'};
$visibility_km = $parsed_json->{'current_observation'}->{'visibility_km'};
$solarradiation = $parsed_json->{'current_observation'}->{'solarradiation'};
$UV = $parsed_json->{'current_observation'}->{'UV'};
$precip_1hr_metric = $parsed_json->{'current_observation'}->{'precip_1hr_metric'};
$precip_today_metric = $parsed_json->{'current_observation'}->{'precip_today_metric'};
echo "The weather in Komoka, ${observation_time}:<br />
${weather}
${icon_url}
<br />
Temperature is ${temp_c} C° and feels like ${feelslike_c} C°.<br />
Heat index is ${heat_index_c} C° and the windchill ${windchill_c} C°. The dewpoint is at ${dewpoint_c} C°.<br />
Wind is from the ${wind_dir} at ${wind_kph} with gusts of ${wind_gust_kph} kph.<br />
The barometric pressure is ${pressure_mb} MB and ${pressure_trend}. There has been ${precip_1hr_metric} mm rain in the last hour, and ${precip_today_metric} mm today so far.<br />
Visibility is ${visibility_km} km. UV index is ${UV} and solar radiation ${solarradiation} W/m<sup>2</sup>.
\n";
?>
The weather in Komoka, Last Updated on March 24, 9:40 AM EDT:
Mostly Cloudy
Temperature is 4 C° and feels like 2 C°.
Heat index is NA C° and the windchill 2 C°. The dewpoint is at -4 C°.
Wind is from the North at 8 with gusts of 12.9 kph.
The barometric pressure is 1022 MB and 0. There has been 0 mm rain in the last hour, and 0 mm today so far.
Visibility is 24.1 km. UV index is 0.7 and solar radiation 199 W/m2.
I don't have a sample of the previous json file but the current json output is
observations
0
stationID "IONTARIO226"
obsTimeUtc "2019-03-26T17:44:46Z"
obsTimeLocal "2019-03-26 13:44:46"
neighborhood "Komoka Village"
softwareType "Cumulus v1.9.4"
country "CA"
solarRadiation 816
lon -81.43488312
realtimeFrequency null
epoch 1553622286
lat 42.95424271
uv 4.7
winddir 360
humidity 23
qcStatus 1
metric
temp 6
heatIndex 6
dewpt -14
windChill 3
windSpeed 8
windGust 14
pressure 1031.36
precipRate 0
precipTotal 0
elev 243
My modified script with the new json data is:
Code: Select all
<?php
$json_string = file_get_contents("https://api.weather.com/v2/pws/observations/current?stationId=IONTARIO226&format=json&units=m&apiKey=NEW API KEY");
$parsed_json = json_decode($json_string);
//observations
$observation_stationID = $parsed_json->{'observations'}->{'0'}->{'stationID'};
$observation_obsTimeUtc = $parsed_json->{'observations'}->{'0'}->{'obsTimeUtc'};
$observation_TimeLocal = $parsed_json->{'observations'}->{'obsTimeLocal'};
$observation_neighborhood = $parsed_json->{'observations'}->{'neighborhood'};
$observation_softwareType = $parsed_json->{'observations'}->{'softwareType'};
$observation_country = $parsed_json->{'observations'}->{'country'};
$observation_solarRadiation = $parsed_json->{'observations'}->{'solarRadiation'};
$observation_lon = $parsed_json->{'observations'}->{'lon'};
$observation_realtimeFrequency = $parsed_json->{'observations'}->{'realtimeFrequency'};
$observation_epoch = $parsed_json->{'observations'}->{'epoch'};
$observation_lat = $parsed_json->{'observations'}->{'lat'};
$observation_uv = $parsed_json->{'observations'}->{'uv'};
$observation_winddir = $parsed_json->{'observations'}->{'winddir'};
$observation_humidity = $parsed_json->{'observations'}->{'hunidity'};
$observation_qcStatus = $parsed_json->{'observations'}->{'qcStatus'};
//metric
$observation_temp = $parsed_json->{'observations'}->{'metric'}->{'temp'};
$observation_heatIndex = $parsed_json->{'observations'}->{'metric'}->{'heatIndex'};
$observation_dewpt = $parsed_json->{'observations'}->{'metric'}->{'dewpt'};
$observation_windChill = $parsed_json->{'observations'}->{'metric'}->{'windChill'};
$observation_windSpeed = $parsed_json->{'observations'}->{'metric'}->{'windSpeed'};
$observation_windGust = $parsed_json->{'observations'}->{'metric'}->{'windGust'};
$observation_pressure = $parsed_json->{'observations'}->{'metric'}->{'pressure'};
$observation_precipRate = $parsed_json->{'observations'}->{'metric'}->{'precipRate'};
$observation_prectpTotal = $parsed_json->{'observations'}->{'metric'}->{'precipTotal'};
echo "The weather at Station ${observation_stationID} ${observation_neighborhood} Ontario, Canada:<br />
${weather}
${icon_url}
<br />
Temperature is ${observation_TimeLocal} C°<br />
The heat index is ${observation_heatIndex} C° and the windchill ${observation_windChill} C°. The dewpoint is at ${observation_dewpt} C°.<br />
Wind is from ${observation_winddir} degrees at ${observation_windSpeed} kph with gusts of ${observation_windGust} kph.<br />
The barometric pressure is ${observation_pressure} MB. There has been ${observation_precipTotal} mm rain so far.<br />
The solar radiation is ${observation_solarRadiation} W/m<sup>2</sup> and UV index is ${observation_uv}.
\n";
?>
Any pointers appreciated,
Paul