You are here

function weather_store_metar in Weather 5

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

Stores parsed METAR data in the database

1 call to weather_store_metar()
weather_get_metar in ./weather.module
Fetches the latest METAR data from the database or internet

File

./weather.module, line 917
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

function weather_store_metar($metar) {

  // if there's already a record in the database with the same ICAO
  // overwrite it
  $sql = "DELETE FROM {weather} WHERE icao='%s'";
  db_query($sql, $metar['icao']);

  // insert the new data
  $sql = "INSERT INTO {weather}\n    (icao, next_update_on, metar_raw)\n    VALUES ('%s', %d, '%s')";

  // calculate the next scheduled update: normally, we use 62
  // minutes after the reported timestamp, to allow the data
  // to propagate to the server servers.
  $next_update_on = $metar['reported_on'] + 62 * 60;

  // However, if the current time is more than 62 minutes
  // over the reported timestamp, allow ten more minutes
  // to not fetch the data on each page request.
  if ($next_update_on < time()) {
    $next_update_on = time() + 10 * 60;
  }
  db_query($sql, $metar['icao'], $next_update_on, $metar['#raw']);
}