2012-10-16 07:44:31 +00:00
|
|
|
|
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
include_once(FWK_PATH.'common/curl.php');
|
|
|
|
|
include_once(FWK_PATH.'common/chiffres.php');
|
|
|
|
|
include_once(FWK_PATH.'common/dates.php');
|
|
|
|
|
$modeDebug=false;
|
|
|
|
|
|
|
|
|
|
$strInfoScript='Usage : '.basename($argv[0]). " <option>
|
2013-06-19 08:24:49 +00:00
|
|
|
|
Mise <EFBFBD> jour des tribunaux comp<EFBFBD>tents pour les codes insee des communes depuis le site du minist<EFBFBD>re de la justice.
|
|
|
|
|
/**@todo : Il faudrait penser <20> mettre <20> jour en automatique la liste des communes depuis le site de l'insee !!!**/
|
2012-10-16 07:44:31 +00:00
|
|
|
|
|
|
|
|
|
Options :
|
2013-06-19 08:24:49 +00:00
|
|
|
|
-d Mode debug (Verbosit<EFBFBD> au maximum et fonctionnement sans timer ni contraintes temporelles)
|
2012-10-16 07:44:31 +00:00
|
|
|
|
|
|
|
|
|
";/* -i:XXXXX Reprendre au code commune Insee XXXXX
|
|
|
|
|
|
|
|
|
|
";*/
|
|
|
|
|
|
|
|
|
|
$argv=$_SERVER['argv'];
|
|
|
|
|
|
|
|
|
|
for ($i=1,$j=0; isset($argv[$i]); $i++) {
|
|
|
|
|
if (substr($argv[$i],0,1)=='-') {
|
|
|
|
|
switch (substr($argv[$i],1,1)) {
|
|
|
|
|
case 'd': $modeDebug=true; break;
|
|
|
|
|
case '-':
|
|
|
|
|
case '?': die($strInfoScript); break;
|
|
|
|
|
default: die('Option '. $argv[$i] . " inconnue !\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** URL = http://www.justice.gouv.fr/recherche-juridictions/popup.php?insee=01053&type=all
|
|
|
|
|
** referer = http://www.justice.gouv.fr/recherche-juridictions/consult.php
|
|
|
|
|
**
|
|
|
|
|
** URL = http://www.insee.fr/fr/nom_def_met/nomenclatures/cog/cog.telechargement.annee.asp?annee=2007
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
$iDb=new WDB('sdv1');
|
|
|
|
|
$table='qualipaysage';
|
|
|
|
|
$urlBase='http://www.qualipaysage.org/pages-securisees/fiche.php?s=';
|
|
|
|
|
|
|
|
|
|
$tabZones=array('codeQE'=>' <b>Code QE n°</b>(?:.*) (\d+)</td>',
|
|
|
|
|
'raiSoc'=>'<td width="310" valign="top" class="textvert4"><strong>(.*)</strong> <br>',
|
|
|
|
|
'adresse'=>'<td width="310" valign="top" class="textvert4"><strong>(?:.*)</strong> <br>(?:.*)(.*)(?:\d\d\d\d\d)',
|
|
|
|
|
'chef'=>'<strong>Responsable\(s\)</strong>(?:.*):</span>(.*)</td>',
|
|
|
|
|
'cp'=>'<br>(?:.*)(\d\d\d\d\d) (?:.*)<br>',
|
|
|
|
|
'ville'=>'<br>(?:.*)(?:\d\d\d\d\d) (.*)<br>',
|
|
|
|
|
'tel'=>'<strong>Tél</strong>(?:.*):(.*)<br>',
|
|
|
|
|
'fax'=>'<strong>Fax</strong>(?:.*):(.*)<br>',
|
|
|
|
|
'mail'=>'<strong>Fax</strong>(?:.*)<br>(.*)<br>',
|
|
|
|
|
'web'=>'<a href="(.*)" target="_blank" class="lnkvert">',
|
|
|
|
|
'anneeBilan'=>'<strong>Année(?:.*)d’exercice : </strong><span class="textvert2"><strong>(\d\d\d\d)</strong>',
|
|
|
|
|
'ca'=>'<strong>CA total(?:.*)</strong> <span class="textvert2"><strong>(.*)</strong>',
|
|
|
|
|
'effectif'=>'<strong>Effectif(?:.*)global :</strong> <span class="textvert2"><strong>(.*)</strong>',
|
|
|
|
|
'numAdh'=>'<strong>N°(?:.*)d\'adhérent : </strong>(.*)<br>',
|
|
|
|
|
'debAct'=>'<strong>Début(?:.*)d\'activité :</strong>(.*)<br>',
|
|
|
|
|
'numCert'=>'<strong>N° de certificat : </strong>(.*)<br>',
|
|
|
|
|
'valCert'=>'<strong>Validité du certificat :</strong>(.*)</td>',
|
|
|
|
|
'siren'=>'<strong>Registre(?:.*)du Commerce :</strong>(.*)<br>',
|
|
|
|
|
'assurance'=>'<strong>Assurance(?:.*):</strong>(.*)<br>',
|
|
|
|
|
'siret'=>'<strong>Code Siret(?:.*):</strong>(.*)</td>',
|
|
|
|
|
'naf'=>'<strong>Code NAF :</strong>(.*)<br>',
|
|
|
|
|
'qualifs[qualifType,qualifClasse,qualifLib,qualifCode]'=>'<p> <strong><span class="textvert4">(.*)- classe :(.*)<br>(?:.*)</span></strong>(?:.*)</p>(?:.*)<span class="textvert2"><strong>(.*)</strong></span><br>(?:.*)</strong>(.*)<br>',
|
|
|
|
|
);
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo date ('Y/m/d - H:i:s')." - D<>but de la mise <20> jour des entreprises '$table'...".EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
|
|
|
|
|
$ret=$iDb->select($table, 'MAX(id)', '1', false);
|
|
|
|
|
$iDeb=$ret[0][0];
|
|
|
|
|
$nbVides=0;
|
|
|
|
|
echo date ('Y/m/d - H:i:s')." - Dernier id entreprise '$table' = $iDeb".EOL;
|
|
|
|
|
|
|
|
|
|
for($i=$iDeb;;$i++) {
|
|
|
|
|
$tabInsert=array('id'=>$i);
|
|
|
|
|
|
|
|
|
|
$ret=$iDb->select($table, 'raiSoc', "id=$i", false);
|
|
|
|
|
if (@$ret[0][0]<>'') continue;
|
|
|
|
|
|
|
|
|
|
$url=$urlBase.$i;
|
|
|
|
|
$page=getUrl($url, '', '', '', false);
|
|
|
|
|
$referer=$url;
|
|
|
|
|
$body=$page['body'];
|
|
|
|
|
$tabHtml=html2array($body, $tabZones);
|
|
|
|
|
//print_r($tabHtml);
|
|
|
|
|
//die();
|
|
|
|
|
|
|
|
|
|
foreach ($tabHtml as $zone=>$data) {
|
|
|
|
|
if (is_array($data)) {
|
|
|
|
|
foreach ($data as $j=>$tabInsert2) {
|
|
|
|
|
$tabInsert2['id']=$i;
|
|
|
|
|
$tabInsert2['num']=$j;
|
|
|
|
|
$tabInsert2['dateInsert']=date('YmdHis');
|
|
|
|
|
if (!$iDb->insert($table.$zone, $tabInsert2, false)) {
|
|
|
|
|
if (mysql_errno()==1062) {
|
|
|
|
|
unset($tabInsert2['dateInsert']);
|
|
|
|
|
$iDb->update($table.$zone, $tabInsert2, "id=$i AND num=$j", false);
|
|
|
|
|
} else {
|
|
|
|
|
print_r($tabInsert2);
|
|
|
|
|
die(mysql_error());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
$tabInsert[$zone]=$data;
|
|
|
|
|
}
|
|
|
|
|
if (count($tabInsert)<10 || $tabInsert['raiSoc']=='') {
|
|
|
|
|
$nbVides++;
|
|
|
|
|
//print_r($tabInsert);
|
|
|
|
|
if ($nbVides<20) continue;
|
|
|
|
|
else {
|
2013-06-19 08:24:49 +00:00
|
|
|
|
echo date('Y/m/d - H:i:s')." - $i : Il semble que le dernier num<75>ro '$table' attribu<62> soit le ".($i-$nbVides).EOL;
|
2012-10-16 07:44:31 +00:00
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$nbVides=0;
|
|
|
|
|
|
|
|
|
|
unset($tabInsert['qualifs']);
|
|
|
|
|
$tabInsert['dateInsert']=date('YmdHis');
|
|
|
|
|
$tabInsert['siren']=str_replace(' ','',$tabInsert['siren']);
|
|
|
|
|
$tabInsert['siret']=str_replace(' ','',$tabInsert['siret']);
|
|
|
|
|
$tabInsert['tel']=str_replace(' ','',$tabInsert['tel']);
|
|
|
|
|
$tabInsert['fax']=str_replace(' ','',$tabInsert['fax']);
|
|
|
|
|
$tabInsert['ca']=str_replace(' ','',str_replace(',','.',$tabInsert['ca']));
|
|
|
|
|
$tabInsert['effectif']=str_replace(' ','',$tabInsert['effectif']);
|
|
|
|
|
$tabInsert['numCert']=str_replace(' ','',$tabInsert['numCert']);
|
|
|
|
|
$tabInsert['debAct']=WDate::dateT('d/m/Y','Ymd',$tabInsert['debAct']);
|
|
|
|
|
$tabInsert['valCert']=WDate::dateT('d/m/Y','Ymd',$tabInsert['valCert']);
|
|
|
|
|
|
|
|
|
|
if (!$iDb->insert($table, $tabInsert, false)) {
|
|
|
|
|
if (mysql_errno()==1062) {
|
|
|
|
|
unset($tabInsert['dateInsert']);
|
|
|
|
|
$iDb->update($table, $tabInsert, "id=$i", false);
|
|
|
|
|
} else {
|
|
|
|
|
print_r($tabInsert);
|
|
|
|
|
die(mysql_error());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//die();
|
|
|
|
|
$nb=count($tabInsert);
|
|
|
|
|
$nb2=@count($tabInsert2);
|
|
|
|
|
echo date('Y/m/d H:i:s')." - $i : $nb zones et $nb2 qualifications".EOL;
|
|
|
|
|
|
|
|
|
|
if ($modeDebug) randsleep(1,2);
|
|
|
|
|
else randsleep(7,21);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
die();
|
|
|
|
|
|
|
|
|
|
?>
|