You are here

function weather_get_metar in Weather 7

Same name and namespace in other branches
  1. 5.6 weather.module \weather_get_metar()
  2. 5 weather.module \weather_get_metar()
  3. 6.5 weather.module \weather_get_metar()

Fetches the latest METAR data from the database or internet.

Parameters

string $icao: ICAO code.

Return value

object METAR data object or FALSE.

2 calls to weather_get_metar()
weather_block_view in ./weather.module
Implement hook_block_view().
weather_search_location in ./weather.forms.inc
Search for a given location.

File

./weather.module, line 661
Display current weather data from many places in the world.

Code

function weather_get_metar($icao) {

  // See if there's a report in the database.
  $icao = drupal_strtoupper($icao);
  $sql = "SELECT * FROM {weather_metar} WHERE icao=:icao";
  $metar = db_query($sql, array(
    ':icao' => $icao,
  ))
    ->fetchObject();

  // If there's no data at all or the data is outdated, try to download it.
  if ($metar == FALSE or $metar->next_update_on <= REQUEST_TIME) {
    module_load_include('inc', 'weather', 'weather_parser');
    weather_refresh_data($icao, $metar);
  }
  return $metar;
}