From Marty, 2 Years ago, written in PHP.
Embed
  1. /*
  2.         Display Metar in WordPress Post or Page
  3.         http://www.flight.org/post-an-aviation-metar-report-into-your-wordpress-post-or-page-with-shortcode
  4. */
  5.  
  6.  
  7. function get_metar($atts, $content = null) {
  8.   extract(shortcode_atts(array(
  9.     'loc' => 'YSSY',
  10.     'cache' => '3600'
  11.   ), $atts));
  12.  
  13.   $transient = "$loc.$metar.$cache";
  14.   $dbresult =  get_transient($transient);
  15.  
  16.   if ($dbresult == true  ) {
  17.    return $dbresult;
  18.   } else {
  19.  
  20.   $loc = strtoupper($loc);
  21.   $fileName = 'http://weather.noaa.gov/pub/data/observations/metar/stations/' . $loc . '.TXT';
  22.    $metar = '';
  23.    $fileData = @file($fileName) or die('METAR not available');
  24.        
  25.     if ($fileData != false) {
  26.      list($i, $date) = each($fileData);
  27.       $utc = strtotime(trim($date));
  28.       $time = date("D, F jS Y g:i A",$utc);
  29.        
  30.         while (list($i, $line) = each($fileData)) {
  31.           $metar .= ' ' . trim($line);
  32.         }
  33.       $result = '<p>' . trim(str_replace('  ', ' ', $metar)) . '</p>';
  34.      }
  35.        
  36.     // $result = "<BLOCKQUOTE>METAR FOR $loc (Issued: $time UTC):$metar</BLOCKQUOTE>";
  37.     set_transient($transient, $result, $cache);
  38.     return $result;
  39.     }
  40. }
  41. add_shortcode('metar', 'get_metar');