[Devel] r455 - branches/dui

svn at agendadulibre.org svn at agendadulibre.org
Dim 1 Nov 19:10:50 CET 2009


Author: ldayot
Date: Sun Nov  1 19:10:49 2009
New Revision: 455

Log:
Permettre l'enchainement des importation des EPN et leur geolocalisation.

Modified:
   branches/dui/findgeogul.php
   branches/dui/importepn.php

Modified: branches/dui/findgeogul.php
==============================================================================
--- branches/dui/findgeogul.php	Sun Nov  1 19:10:07 2009	(r454)
+++ branches/dui/findgeogul.php	Sun Nov  1 19:10:49 2009	(r455)
@@ -18,12 +18,11 @@
   header("Location:" . calendar_absolute_url());
 }
 
-calendar_setlocale();
-
 put_header("Geolocalise les GULs");
-
+calendar_setlocale();
 echo "<h2>G&eacute;olocalise les GULs</h2>";
 
+$last=0;
 
 $lug_id = get_safe_integer('id', 0);
 if ($lug_id>0)
@@ -38,7 +37,9 @@
   }
 else
   {
-    $lug_res = $db->query ("SELECT * FROM lugs WHERE latitude=0 OR latitude IS NULL LIMIT 0,500");
+    $lug_res = $db->query ("SELECT * FROM lugs WHERE (latitude=0 OR latitude IS NULL) ".
+			" AND id>". get_safe_integer('from', 0).
+			" ORDER BY id LIMIT 0,100");
   }
 
 $count_ok = $count_nok = 0;
@@ -49,22 +50,26 @@
     $url_gps = "http://maps.google.com/maps/geo?q=".
       $lug->address. " ". $lug->postalcode. " ". $lug->city. " France&output=csv&key=ABQIAAAATndsWAV5Q2y7pRRi-22W_hTxw9fvAnrsiYejTsRxd4b0cj9HKxSNCXUxAANaoACDzXWznNLVPto_jA";
     $gps_file = file(str_replace(" ", "+", $url_gps), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
-    if ($lug_id>0)
+    /*if ($lug_id>0)
       {
         echo str_replace(" ", "+", $url_gps)."<br/>";
         print_r($gps_file);
-      }
+      }*/
     list(,,$lug->latitude, $lug->longitude) = explode(",", $gps_file[0]);
+		$last = $lug->id;
     
     if ($lug->latitude>0) 
       {
         echo "+ ";
         $count_ok++;
       }
+
     else// on prend les coordonnees de la ville si on ne trouve pas
       {
         echo "-{$lug->id}\n";
         $count_nok++;
+				continue;
+/*
         if ($lug->city == "")
           continue; // no city
 
@@ -85,8 +90,8 @@
         $city = $db->fetchObject($city);
         $lug->longitude = $city->longitude;
         $lug->latitude  = $city->latitude;
-      }
-              
+*/
+      }              
     $sql = "UPDATE lugs SET latitude='{$lug->latitude}', longitude='{$lug->longitude}' WHERE id='{$lug->id}'";
     $db->query($sql);
 
@@ -95,6 +100,6 @@
   echo "\n\n<h3>Termin&eacute;</h3>\n";
   echo "<p>Ok : $count_ok</p><p>Pas Ok : $count_nok</p>\n";
 
-  echo "<p><a href=\"findgeogul.php\">Relancer le script</a></p>\n";
+  echo "<p><a href=\"findgeogul.php?from=$last\">Relancer le script pour les lieux suivants</a></p>\n";
 
 ?>

Modified: branches/dui/importepn.php
==============================================================================
--- branches/dui/importepn.php	Sun Nov  1 19:10:07 2009	(r454)
+++ branches/dui/importepn.php	Sun Nov  1 19:10:49 2009	(r455)
@@ -25,7 +25,7 @@
 
 $url = "http://delegation.internet.gouv.fr/bddui/api/accespublic/index.php";
 $repertoire = "?commande=choix&preserve=1";
-//$repertoire = "?commande=choix&IdRegion=2";
+$repertoire = "?commande=choix&IdRegion=". $_GET['region'];
 
 $lignes = file($url. $repertoire, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
 $n=0;
@@ -44,6 +44,7 @@
       {
         $id = substr($ligne, $pos+$longTexteLien, 4);
         echo ++$n. " (". $id. ") ";
+				if (isset($_GET['min']) && $n<$_GET['min']) { echo "<br/>"; continue; }
         $description = file($url. "?". $texteLien. $id, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
         $nextIs=false;
         foreach ($fieldsDui2Adl as $field) $epn[$field]="";
@@ -89,8 +90,10 @@
               }
           }
           
-        $epn['address'] = str_ireplace($epn['postalcode'], "", $epn['address']);
-        $epn['address'] = str_ireplace($epn['city'], "", $epn['address']);
+        $epn['address'] = str_replace($epn['postalcode'], "", $epn['address']);
+        $epn['address'] = str_replace($epn['city'], "", $epn['address']);
+        $epn['address'] = str_replace(strtolower($epn['city']), "", $epn['address']);
+        $epn['address'] = str_replace(strtoupper($epn['city']), "", $epn['address']);
         
         $epn['comment'] =
           ($epn['services']>"" ? "Services : ". $epn['services']. "<br/>\n" : "").
@@ -130,4 +133,5 @@
     return isset($element) ? $element : false;
   }
 
+echo "<p>Terminé</p>";
 ?>


Plus d'informations sur la liste de diffusion Devel