GENWiki

Premier IT Outsourcing and Support Services within the UK

User Tools

Site Tools


php:parse_the_noaa_space_weather_data_in_php
function getSpaceWeather() {
    $url = "https://services.swpc.noaa.gov/json/solar_probabilities.json"; // The NOAA url
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch); // Read the data from the NOAA Url into $response
 
    curl_close($ch);
    $data = json_decode($response); // Decode the response into an object
 
    $sr=(array) $data[0]; // Cast the JSON object into an array
 
    $html="C_class ".$sr["c_class_1_day"]; 
    $html.=" M_class ".$sr["m_class_1_day"];
    $html.=" X_class ".$sr["x_class_1_day"];
    $html.=" 10mev ".$sr["10mev_protons_1_day"];
    $html.=" 100mev ".$sr["100mev_protons_1_day"];
    $html.=" Polar ".$sr["polar_cap_absorption"];
 
    return $html; // return back the HTML
}

This API is really easy to use, and returns a 3 day window for C, M and X Class as well as 10mev and 100mev proton readings. The data is returned from the API and dumped into an Array() so you can easily change the output.

In its default config (above) it returns HTML, but can easily be changed to return the $sr array by removing the $html… lines and changing the return $html; to be return $sr;

  • $sr["c_class_1_day"];
  • $sr["m_class_1_day"];
  • $sr["x_class_1_day"];
  • $sr["10mev_protons_1_day"];
  • $sr["100mev_protons_1_day"];
  • $sr["polar_cap_absorption"];
echo getSpaceWeather();
/data/webs/external/dokuwiki/data/pages/php/parse_the_noaa_space_weather_data_in_php.txt · Last modified: 2019/08/01 11:37 by genadmin

Was this page helpful?-12+1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki