home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / metar-basic.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.7 KB  |  68 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Alexander Wirtz <alex@pc4p.net>                             |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: metar-basic.php,v 1.8 2003/12/31 23:31:22 eru Exp $
  20.  
  21. require_once "Services/Weather.php";
  22.  
  23. // Object initialization - error checking is important, because of
  24. // handling exceptions such as missing PEAR modules
  25. $metar = &Services_Weather::service("METAR", array("debug" => 0));
  26. if (Services_Weather::isError($metar)) {
  27.     die("Error: ".$metar->getMessage()."\n");
  28. }
  29.  
  30. // Set parameters for DB access, needed for location searches
  31. $metar->setMetarDB("sqlite://localhost//usr/local/lib/php/data/Services_Weather/servicesWeatherDB");
  32. if (Services_Weather::isError($metar)) {
  33.     echo "Error: ".$metar->getMessage()."\n";
  34. }
  35.  
  36. /* Erase comments to enable caching
  37. $metar->setCache("file", array("cache_dir" => "/tmp/cache/"));
  38. if (Services_Weather::isError($metar)) {
  39.     echo "Error: ".$metar->getMessage()."\n";
  40. }
  41. */
  42.  
  43. $metar->setUnitsFormat("custom", array(
  44.     "wind" => "kt",
  45.     "vis" => "km",
  46.     "temp" => "c",
  47.     "pres" => "hpa",
  48.     "rain" => "in"));
  49. $metar->setDateTimeFormat("d.m.Y", "H:i");
  50.  
  51. // First get code for location
  52. $search = $metar->searchLocation("Bonn, Germany");
  53. if (Services_Weather::isError($search)) {
  54.     die("Error: ".$search->getMessage()."\n");
  55. }
  56.  
  57. // Now iterate through available functions for retrieving data
  58. foreach (array("getLocation", "getWeather", "getForecast") as $function) {
  59.     $data = $metar->$function($search);
  60.     if (Services_Weather::isError($data)) {
  61.         echo "Error: ".$data->getMessage()."\n";
  62.         continue;
  63.     }
  64.  
  65.     var_dump($data);
  66. }
  67. ?>
  68.