Author Topic: Importing WU conditions as a text file  (Read 1261 times)

0 Members and 1 Guest are viewing this topic.

Offline Ian.

  • Forecaster
  • *****
  • Posts: 459
    • Chatteris Weather
Importing WU conditions as a text file
« on: March 10, 2017, 01:43:49 AM »
Hi,

Not sure if this is possible, but here goes -

I would like to generate a text file from Weather Underground local station, downloading only a few key details, such as rain, wind speed and temperature so the data could be incorporated in a text summary file.

The update period would be hourly and would be done by a PC rather than any server side scripting.

The reason for the file is to allow it to be linked to a ham radio application which reads WX text files.

CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Importing WU conditions as a text file
« Reply #1 on: March 10, 2017, 06:03:49 AM »
You could use the history page with XML data and always load the latest values, only parsing the parameters you want

The URL is as follows:

http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=XXXXXXXX&format=XML


XXXXX is your WU ID

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 519
    • Tyler Texas Weather
Re: Importing WU conditions as a text file
« Reply #2 on: March 10, 2017, 08:17:13 AM »
I would like to generate a text file from Weather Underground local station, downloading only a few key details, such as rain, wind speed and temperature so the data could be incorporated in a text summary file.

This might be a little easier to use.

http://api.wunderground.com/api/a486e18c28325f44/conditions/q/pws:ICAMBRID16.json

Steve

Offline Ian.

  • Forecaster
  • *****
  • Posts: 459
    • Chatteris Weather
Re: Importing WU conditions as a text file
« Reply #3 on: March 10, 2017, 11:35:54 AM »
Hi & thanks for the speedy replies

Really encouraged that I can get the information, I'm definatly no scripter, so how do I extract the information into a text file, for example "temp_c":12.9, "wind_dir":"SSE", "weather":"Overcast", to read:

The weather is "weather":"Overcast" with a wind blowing "wind_dir":"SSE" and a temperture of "temp_c":12.9 centigrade.

Sorry for being so noddy
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Importing WU conditions as a text file
« Reply #4 on: March 10, 2017, 11:38:38 AM »
You cannot do this by pure HTML.

You will need to use PHP, load the JSON/XML file, then parse it into a string/array and then dynamically insert it into the sentence.

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 519
    • Tyler Texas Weather
Re: Importing WU conditions as a text file
« Reply #5 on: March 10, 2017, 12:04:59 PM »
Try something like this. Remember to get an API Key from WeatherUnderground first at https://www.wunderground.com/weather/api/d/pricing.html
Code: [Select]
<?php
  $json_string 
file_get_contents("http://api.wunderground.com/api/your-api-key-goes-here/conditions/q/pws:ICAMBRID16.json");
  
$parsed_json json_decode($json_string);
  
$weather $parsed_json->{'current_observation'}->{'weather'};
  
$temp_c $parsed_json->{'current_observation'}->{'temp_c'};
  
$wind_dir $parsed_json->{'current_observation'}->{'wind_dir'};  
  echo 
"The weather is ${weather} with a wind blowing ${wind_dir} and a temperature of ${temp_c} degrees centigrade.\n";
?>


Steve

Offline Ian.

  • Forecaster
  • *****
  • Posts: 459
    • Chatteris Weather
Re: Importing WU conditions as a text file
« Reply #6 on: March 10, 2017, 12:55:10 PM »
Thanks guys you have been really helpful, all works fine.

To make it work for me I'll paste the result into notepad file and the jobs good.

All the best
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz