Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv30114
Modified Files:
configurator.php data_retrieval.php db_dba.php db_mysql.php
db_null.php defaults-dist.php index.php metar_parser.php
stations.csv
Log Message:
The reports now include the location... just use get_location() to
retrieve it.
This means that what was know as a 'station' before is now known as
'icao'. So the functions have been renamed - I hope I haven't
forgotten something.
Index: configurator.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/configurator.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- configurator.php 2001/05/19 16:22:09 1.4
+++ configurator.php 2001/05/20 13:07:16 1.5
@@ -7,12 +7,60 @@
<?php
+/**
+ * A basic property.
+ *
+ */
class property {
+
+ /**
+ * The name of the property
+ *
+ * @var string
+ * @access private
+ */
var $name;
+
+ /**
+ * The description of the property
+ *
+ * This is the text that is displayed to the user.
+ *
+ * @var string
+ * @access private
+ */
var $description;
+
+ /**
+ * The data of the property
+ *
+ * If the property can one out of several different values, then this should be an
+array, where the first entry is the default. Else it should be a string.
+ *
+ * @var mixed
+ * @access private
+ */
var $data;
+
+ /**
+ * A header used in the each line in the config-file.
+ *
+ * All lines in the file start with '$this->properties['property'] = '. This
+variable holds a string like that, where 'property' is replaced as apropriate.
+ *
+ * @var string
+ * @access private
+ */
var $config_header;
+ /**
+ * The constructor.
+ *
+ * It takes care of storing the input in the object, and generates the
+config_header.
+ *
+ * @param string the name of the property
+ * @param mixed the data the property should hold
+ * @param string the description
+ * @access public
+ */
function property($name, $data, $description) {
$this->name = $name;
$this->description = $description;
@@ -20,10 +68,22 @@
$this->config_header = "/* $name */\n\$this->properties['$name'] = ";
}
+ /**
+ * Returns the name of the property.
+ *
+ * @return string The name, without any formatting.
+ * @access public
+ */
function get_name() {
return $this->name;
}
+ /**
+ * Returns the description of the property.
+ *
+ * @return string The description, without any formatting.
+ * @access public
+ */
function get_description() {
return $this->description;
}
@@ -144,8 +204,8 @@
"even if it's too old. But if the data isn't there, " .
"it will still fetch new data from the Internet.");
-$properties['station'] =
- new text('station',
+$properties['icao'] =
+ new text('icao',
'EKYT',
'This will be the default station used by PHP Weather. ' .
'You should enter a four-letter ICAO.');
Index: data_retrieval.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/data_retrieval.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- data_retrieval.php 2001/04/29 18:39:15 1.7
+++ data_retrieval.php 2001/05/20 13:07:16 1.8
@@ -24,6 +24,14 @@
var $metar;
/**
+ * The location of the station, eg. something like 'Aalborg, Denmark'.
+ *
+ * @var string
+ */
+ var $location;
+
+
+ /**
* Constructor
*
* This sets the station.
@@ -36,31 +44,32 @@
$this->db_layer($input);
/* Then we set the station. */
- $this->set_station($this->properties['station']);
+ $this->set_icao($this->properties['icao']);
}
/**
- * Returns the station.
+ * Returns the current ICAO.
*
* @return string The station-ICAO
* @access public
*/
- function get_station() {
- return $this->properties['station'];
+ function get_icao() {
+ return $this->properties['icao'];
}
/**
- * Sets the station.
+ * Sets the station or rather the ICAO.
*
- * It also clear the METAR and decoded metar if the station is different from the
old one. If the new station is the same as the old one, nothing is changed.
+ * It also clear the METAR and decoded METAR if the station is different from the
+old one. If the new station is the same as the old one, nothing is changed.
*
- * @param string $new_station The ICAO of the new station.
+ * @param string The ICAO of the new station.
* @access public
*/
- function set_station($new_station) {
- if ($new_station != $this->get_station()) {
- $this->properties['station'] = strtoupper($new_station);
+ function set_icao($new_icao) {
+ if ($new_icao != $this->get_icao()) {
+ $this->properties['icao'] = strtoupper($new_icao);
+ $this->location = '';
$this->metar = '';
$this->decoded_metar = '';
}
@@ -102,14 +111,13 @@
* @return string The raw METAR.
* @access public
*/
-
function get_metar_from_db() {
if (!$this->db->connect()) {
return false;
}
- if ($data = $this->db->get_metar($this->get_station())) { /* found station */
+ if ($data = $this->db->get_metar($this->get_icao())) { /* found station */
$this->notice('Found the METAR in the database');
list($metar, $timestamp) = $data;
/* We set the METAR right away, and then count on
@@ -122,22 +130,22 @@
* still fresh. Either way - we return the METAR we found in
* the database.
*/
- $this->notice('Using previously cached METAR for <code>' .
$this->get_station() . '</code>. The METAR expires in ' . ($timestamp + 3600 - time())
. ' seconds.');
+ $this->notice('Using previously cached METAR for <code>' .
+$this->get_location() . '</code>. The METAR expires in ' . ($timestamp + 3600 -
+time()) . ' seconds.');
return $metar;
} else {
/* The METAR is too old, so we fetch a new */
- $this->notice('The METAR for <code>' . $this->get_station() . '</code> was ' .
(time() - 3600 - $timestamp) . ' seconds too old.');
+ $this->notice('The METAR for <code>' . $this->get_location() . '</code> was '
+. (time() - 3600 - $timestamp) . ' seconds too old.');
return $this->get_metar_from_web(false);
}
} else {
/* We need to get a new METAR from the web. */
- $this->notice('New station <code>' . $this->get_station() . '</code> - fetching
a new METAR.');
+ $this->notice('New station <code>' . $this->get_location() . '</code> -
+fetching a new METAR.');
return $this->get_metar_from_web(true);
}
}
/**
- * Fetches a METAR for the Internet.
+ * Fetches a METAR from the Internet.
*
* The METAR is fetched via HTTP from the National Weather Services public server
at http://weather.noaa.gov.
*
@@ -147,10 +155,10 @@
*/
function get_metar_from_web($new_station) {
$metar = '';
- $station = $this->get_station();
+ $icao = $this->get_icao();
/* We use the @file notation here because it might fail. */
- $file =
@file("http://weather.noaa.gov/pub/data/observations/metar/stations/$station.TXT");
+ $file =
+@file("http://weather.noaa.gov/pub/data/observations/metar/stations/$icao.TXT");
/* Here we test to see if we actually got a METAR. */
if (is_array($file)) {
/* The first line in the file is the date */
@@ -210,16 +218,25 @@
/* We then cache the METAR in our database */
if ($new_station) {
- $this->notice('Inserting new METAR for <code>' . $this->get_station() .
'</code>');
- $this->db->insert_metar($station, $metar, $timestamp);
+ $this->notice('Inserting new METAR for <code>' . $this->get_location() .
+'</code>');
+ $this->db->insert_metar($icao, $metar, $timestamp);
} else {
- $this->notice('Updating METAR for <code>' . $this->get_station() . '</code>');
- $this->db->update_metar($station, $metar, $timestamp);
+ $this->notice('Updating METAR for <code>' . $this->get_location() . '</code>');
+ $this->db->update_metar($icao, $metar, $timestamp);
}
/* We update and return the METAR */
$this->metar = $metar;
return $metar;
}
+
+ function get_location() {
+ if (!empty($this->location)) {
+ return $this->location;
+ } else {
+ return $this->location = $this->db->lookup_icao($this->get_icao());
+ }
+ }
+
}
?>
Index: db_dba.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_dba.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- db_dba.php 2001/05/19 16:17:53 1.6
+++ db_dba.php 2001/05/20 13:07:16 1.7
@@ -151,11 +151,11 @@
* @return string The full name of the station, including country.
* @access public
*/
- function lookup_station($station) {
- if (dba_exists($station, $this->link_stations_id)) {
- return dba_fetch($station, $this->link_stations_id);
+ function lookup_icao($icao) {
+ if (dba_exists($icao, $this->link_stations_id)) {
+ return dba_fetch($icao, $this->link_stations_id);
} else {
- return $station;
+ return $icao;
}
}
Index: db_mysql.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_mysql.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- db_mysql.php 2001/05/19 16:17:53 1.5
+++ db_mysql.php 2001/05/20 13:07:16 1.6
@@ -213,14 +213,14 @@
* @return string The full name of the station, including country.
* @access public
*/
- function lookup_station($station) {
+ function lookup_icao($icao) {
$this->query('SELECT name, country FROM ' . $this->properties['db_stations'] .
- "WHERE icao = '$station'");
+ "WHERE icao = '$icao'");
if ($this->num_rows()) {
$row = $this->fetch_row();
return "$row[0], $row[1]";
} else {
- return $station;
+ return $icao;
}
}
Index: db_null.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_null.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- db_null.php 2001/04/26 13:11:00 1.2
+++ db_null.php 2001/05/20 13:07:16 1.3
@@ -79,6 +79,20 @@
function get_metar($station) {
return '';
}
+
+ /**
+ * Pretends to translate an ICAO into a station name
+ *
+ * This function doesn't really do anything.
+ *
+ * @param string The ICAO one want's to translate.
+ * @return string The ICAO unchanged.
+ * @access public
+ */
+ function lookup_icao($icao) {
+ return $icao;
+ }
+
}
?>
Index: defaults-dist.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/defaults-dist.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- defaults-dist.php 2001/05/19 16:20:13 1.4
+++ defaults-dist.php 2001/05/20 13:07:16 1.5
@@ -13,7 +13,7 @@
*/
$this->properties['always_use_db'] = false; /* data_retrieval.php */
-$this->properties['station'] = 'EKYT'; /* data_retrieval.php */
+$this->properties['icao'] = 'EKYT'; /* data_retrieval.php */
$this->properties['db_hostname'] = ''; /* db_common.php */
$this->properties['db_database'] = ''; /* db_common.php */
Index: index.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/index.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- index.php 2001/05/19 16:24:00 1.9
+++ index.php 2001/05/20 13:07:16 1.10
@@ -63,7 +63,7 @@
for ($i = 0; $i < $num_stations; $i++) {
echo "<h1>$stations[$i]</h1>\n";
- $obj->set_station($stations[$i]);
+ $obj->set_icao($stations[$i]);
$obj->print_pretty();
echo '<blockquote><code>' . $obj->metar . "</code></blockquote>";
}
Index: metar_parser.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/metar_parser.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- metar_parser.php 2001/04/26 13:11:00 1.5
+++ metar_parser.php 2001/05/20 13:07:16 1.6
@@ -125,8 +125,7 @@
$decoded_metar['remarks'] = '';
$decoded_metar['metar'] = $this->get_metar();
- $decoded_metar['location'] = $this->get_station();
- // $this->lookup_icao($this->get_station());
+ $decoded_metar['location'] = $this->get_location();
$parts = explode(' ', $this->metar);
$num_parts = count($parts);
Index: stations.csv
===================================================================
RCS file: /cvsroot/phpweather/phpweather/stations.csv,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- stations.csv 2001/05/19 16:15:09 1.1
+++ stations.csv 2001/05/20 13:07:16 1.2
@@ -4,8 +4,7 @@
# A compilation of airports from
# http://weather.noaa.gov/weather/ccworld.html
#
-# Made by Sven-Erik
-# Andersen <[EMAIL PROTECTED]>
+# Made by Sven-Erik Andersen <[EMAIL PROTECTED]>
## Albania ##
LATI;Tirana
_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins