getRawWeatherData() public method

Directly returns the xml/json/html string returned by OpenWeatherMap for the current weather.
public getRawWeatherData ( array | integer | string $query, string $units = 'imperial', string $lang = 'en', string $appid = '', string $mode = 'xml' ) : string
$query array | integer | string The place to get weather information for. For possible values see ::getWeather.
$units string Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
$lang string The language to use for descriptions, default is 'en'. For possible values see http://openweathermap.org/current#multi.
$appid string Your app id, default ''. See http://openweathermap.org/appid for more details.
$mode string The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
return string Returns false on failure and the fetched data in the format you specified on success. Warning: If an error occurs, OpenWeatherMap ALWAYS returns json data.
コード例 #1
0
// Example 8: Get information about the clouds.
echo "<br /><br />\n\n\nEXAMPLE 8<hr />\n\n\n";
// The number in braces seems to be an indicator how cloudy the sky is.
echo "Clouds: " . $weather->clouds->getDescription() . " (" . $weather->clouds . ")";
echo "<br />\n";
// Example 9: Get information about precipitation.
echo "<br /><br />\n\n\nEXAMPLE 9<hr />\n\n\n";
echo "Precipation: " . $weather->precipitation->getDescription() . " (" . $weather->precipitation . ")";
echo "<br />\n";
// Example 10: Show copyright notice. WARNING: This is no offical text. This hint was created regarding to http://www.http://openweathermap.org/copyright .
echo "<br /><br />\n\n\nEXAMPLE 10<hr />\n\n\n";
echo $owm::COPYRIGHT;
echo "<br />\n";
// Example 11: Get raw xml data.
echo "<br /><br />\n\n\nEXAMPLE 11<hr />\n\n\n";
echo "<pre><code>" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'xml')) . "</code></pre>";
echo "<br />\n";
// Example 12: Get raw json data.
echo "<br /><br />\n\n\nEXAMPLE 12<hr />\n\n\n";
echo "<code>" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'json')) . "</code>";
echo "<br />\n";
// Example 13: Get raw html data.
echo "<br /><br />\n\n\nEXAMPLE 13<hr />\n\n\n";
echo $owm->getRawWeatherData('Berlin', $units, $lang, null, 'html');
echo "<br />\n";
// Example 14: Error handling.
echo "<br /><br />\n\n\nEXAMPLE 14<hr />\n\n\n";
// Try wrong city name.
try {
    $weather = $owm->getWeather("ThisCityNameIsNotValidAndDoesNotExist", $units, $lang);
} catch (OWMException $e) {
コード例 #2
0
echo "{$lf}{$lf} EXAMPLE 9{$lf}";
echo 'Precipation: ' . $weather->precipitation->getDescription() . ' (' . $weather->precipitation . ')';
echo $lf;
// Example 10: Show copyright notice. WARNING: This is no official text. This hint was created by looking at http://www.http://openweathermap.org/copyright .
echo "{$lf}{$lf} EXAMPLE 10{$lf}";
echo $owm::COPYRIGHT;
echo $lf;
// Example 11: Retrieve weather icons.
echo "{$lf}{$lf} EXAMPLE 11{$lf}";
$weather = $owm->getWeather('Berlin');
echo $weather->weather->icon;
echo $lf;
echo $weather->weather->getIconUrl();
// Example 12: Get raw xml data.
echo "{$lf}{$lf} EXAMPLE 12{$lf}";
$xml = $owm->getRawWeatherData('Berlin', $units, $lang, null, 'xml');
if ($cli) {
    echo $xml;
} else {
    echo '<pre><code>' . htmlspecialchars($xml) . '</code></pre>';
}
echo $lf;
// Example 13: Get raw json data.
echo "{$lf}{$lf} EXAMPLE 13{$lf}";
$json = $owm->getRawWeatherData('Berlin', $units, $lang, null, 'json');
if ($cli) {
    echo $json;
} else {
    echo '<pre><code>' . htmlspecialchars($json) . '</code></pre>';
}
echo $lf;
コード例 #3
0
 /**
  * Directly returns the xml/json/html string returned by OpenWeatherMap for the current weather.
  *
  * @param array|int|string $query The place to get weather information for. For possible values see below.
  * @param string           $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
  * @param string           $lang  The language to use for descriptions, default is 'en'. For possible values see below.
  * @param string           $mode  The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
  * @return string
  */
 public function getRawWeatherData($query, $units = null, $lang = null, $mode = null)
 {
     return $this->service->getRawWeatherData($query, empty($units) ? $this->units : $units, empty($lang) ? $this->lang : $lang, $this->api_key, empty($mode) ? $this->mode : $mode);
 }
コード例 #4
0
 /**
  * Get station's datas.
  *
  * @return  array     OWM collected datas.
  * @since    2.0.0
  */
 public function get_datas()
 {
     $this->last_owm_warning = '';
     $this->last_owm_error = '';
     if (get_option('live_weather_station_owm_account')[1] == 1 || get_option('live_weather_station_owm_account')[0] == '') {
         $this->owm_datas = array();
         return array();
     }
     try {
         $this->synchronize_owm();
         $this->owm_datas = array();
         $stations = $this->get_located_stations_list();
         $owm = new OpenWeatherMap();
         foreach ($stations as $key => $station) {
             $values = $this->get_owm_datas_array($owm->getRawWeatherData(array('lat' => $station['loc_latitude'], 'lon' => $station['loc_longitude']), 'metric', 'en', get_option('live_weather_station_owm_account')[0], 'json'), $station, $key);
             if (isset($values) && is_array($values)) {
                 $this->owm_datas[] = $values;
             }
         }
         $this->store_owm_datas();
     } catch (Exception $ex) {
         if (strpos($ex->getMessage(), 'Invalid API key') > -1) {
             $this->last_owm_error = __('Wrong OpenWeatherMap API key.', 'live-weather-station');
         } else {
             $this->last_owm_warning = __('Temporary unable to contact OpenWeatherMap servers. Retry will be done shortly.', 'live-weather-station');
         }
         return array();
     }
     return $this->owm_datas;
 }