CVS: phpweather/db pw_db_common.php,1.8,1.9
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-03-26 00:11:07
|
Update of /cvsroot/phpweather/phpweather/db In directory usw-pr-cvs1:/tmp/cvs-serv23067 Modified Files: pw_db_common.php Log Message: This keeps getting better and better... :-) Index: pw_db_common.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/db/pw_db_common.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- pw_db_common.php 25 Mar 2002 23:50:10 -0000 1.8 +++ pw_db_common.php 26 Mar 2002 00:11:04 -0000 1.9 @@ -79,6 +79,7 @@ $inserted = 0; $updated = 0; + $skipped = 0; while (!feof($fp)) { @@ -102,24 +103,31 @@ /* The ICAO is always the first four characters in the METAR: */ $icao = substr($metar, 0, 4); - if ($this->get_metar($icao)) { - $this->update_metar($icao, addslashes($metar), $timestamp); - $updated++; + if (list($m, $t) = $this->get_metar($icao)) { + if ($t < $timestamp) { + /* The METAR in the database is older than the new METAR, so + * we go ahead with the update: */ + $this->update_metar($icao, addslashes($metar), $timestamp); + $updated++; + } else { + $skipped++; + } } else { + /* There's no timestamp to check against in this case: */ $this->insert_metar($icao, addslashes($metar), $timestamp); $inserted++; } - if (($inserted + $updated) % 100 == 0) { - printf("Inserted %6d new METARs, updated %6d METARs...\n", - $inserted, $updated); + if (($inserted + $updated + $skipped) % 100 == 0) { + printf("Inserted: %5d, Updated: %5d, Skipped: %5d\n", + $inserted, $updated, $skipped); flush(); } } /* while (!feof($fp)) */ - printf("Inserted %6d new METARs, updated %6d METARs...\n", - $inserted, $updated); + printf("Inserted: %5d, Updated: %5d, Skipped: %5d\n", + $inserted, $updated, $skipped); fclose($fp); } |