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 = $noTimer = 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
- t Pas de timer du tout
" ;/* -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 't' : $noTimer = true ; break ;
//case 'i': $iDeb=substr($argv[$i],3); 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' );
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 avec RPS... " . EOL ;
2012-10-16 07:44:31 +00:00
$url = 'http://www.travailler-mieux.gouv.fr/spip.php?page=stress_liste&cla=1' ;
$page = getUrl ( $url , '' , '' , '' , false );
$referer = $url ;
$body = $page [ 'body' ];
if ( preg_match_all ( '/<li><a href="spip\.php\?page=stress_entreprise&idfent=(\d+)">(.*)<\/a>(.*)<\/li>/Uis' , $body , $matches )) {
$tabEnt = $tabTri = array ();
foreach ( $matches [ 1 ] as $i => $idfent ) {
$tabEnt [ '_' . $idfent ] = array ( 'idfent' => $idfent ,
'raiSoc' => html_entity_decode ( trim ( $matches [ 2 ][ $i ])),
'cpVille' => html_entity_decode ( trim ( preg_replace ( '/^\s+\-/' , '' , $matches [ 3 ][ $i ]))),
);
$tabTri [] = '_' . $idfent ;
}
}
$nbEnt = count ( $tabEnt );
shuffle ( $tabTri );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - Il y a $nbEnt entreprises avec RPS <20> v<> rifier... " . EOL ;
2012-10-16 07:44:31 +00:00
$ret = $iDb -> select ( 'gouv_rps' , 'idfent, dateMAJ, dateInsert*1 as dateInsert, dateUpdate*1 as lastUpdate' , '1' , false , MYSQL_ASSOC );
$nbEntEnBase = 0 ;
foreach ( $ret as $j => $tmp ) {
$idfent = $tmp [ 'idfent' ];
if ( $tmp [ 'dateInsert' ] > $tmp [ 'lastUpdate' ]) $dateUpdate = $tmp [ 'dateInsert' ];
else $dateUpdate = $tmp [ 'lastUpdate' ];
$tabEnt [ '_' . $idfent ][ 'lastMajBase' ] = $dateUpdate ;
$tabEnt [ '_' . $idfent ][ 'lastMajSite' ] = $tmp [ 'dateMAJ' ];
$nbEntEnBase ++ ;
}
echo date ( 'Y/m/d - H:i:s' ) . " - Il y a $nbEntEnBase entreprises avec RPS en base... " . EOL ;
foreach ( $tabTri as $i => $idfent_ ) {
$idfent = preg_replace ( '/^_/' , '' , $idfent_ );
$libEnt = $tabEnt [ $idfent_ ];
2013-06-19 08:24:49 +00:00
// Pour l'instant si d<> j<EFBFBD> en base, aucune MAJ
2012-10-16 07:44:31 +00:00
if ( isset ( $tabEnt [ $idfent_ ][ 'lastMajSite' ]) && ( $tabEnt [ $idfent_ ][ 'lastMajSite' ] > 0 )) continue ;
$url = " http://www.travailler-mieux.gouv.fr/spip.php?page=stress_entreprise&idfent= $idfent " ;
$page = getUrl ( $url , '' , '' , $referer , false );
$body = $page [ 'body' ];
//print_r($page);
//die();
/*
< div id = " onecol " >
2013-06-19 08:24:49 +00:00
< div class = " titre " >< p > Suivi des négociations sur la prévention des RPS </ p ></ div >
2012-10-16 07:44:31 +00:00
< div class = " liste " >
< div class = " top " ></ div >
< div class = " middle " >
< div class = " titre " >
< h1 > FONDATION BON SAUVEUR D ' ALBY </ h1 >
</ div >
< div class = " notalpha " >
< div id = " regions " >
< div class = " corps " >
2013-06-19 08:24:49 +00:00
< p >< em > Fiche mise à jour le 18 / 02 / 2010 </ em ></ p >< h2 ></ h2 >
< h2 class = " bigger " > Informations générales </ h2 >
2012-10-16 07:44:31 +00:00
< div class = " rowfiche " >
< span class = " librfiche " > Raison sociale :</ span >
< span class = " fieldrfiche " > FONDATION BON SAUVEUR D ' ALBY </ span >
</ div >
< div class = " rowfiche " >
< span class = " librfiche " > Code postal :</ span >
< span class = " fieldrfiche " > 81000 </ span >
</ div >
< div class = " rowfiche " >
< span class = " librfiche " > Ville :</ span >
< span class = " fieldrfiche " > ALBI </ span >
</ div >
< div class = " rowfiche " >
2013-06-19 08:24:49 +00:00
< span class = " librfiche " >< acronym title = " Système d'Identification du Répertoire des Entreprises " > SIREN </ acronym > :</ span >
2012-10-16 07:44:31 +00:00
< span class = " fieldrfiche " > 320662612 </ span >
</ div >
< div class = " rowfiche " >
2013-06-19 08:24:49 +00:00
< span class = " librfiche " > Département :</ span >
2012-10-16 07:44:31 +00:00
< span class = " fieldrfiche " > 81 - Tarn </ span >
</ div >
< div class = " rowfiche " >
2013-06-19 08:24:49 +00:00
< span class = " librfiche " > Région :</ span >
< span class = " fieldrfiche " >< a href = " spip.php?page=stress_region&idreg=15 " > Midi - Pyrénées </ a ></ span >
2012-10-16 07:44:31 +00:00
</ div >
< div class = " etire " >& nbsp ; </ div >
2013-06-19 08:24:49 +00:00
< h2 class = " bigger " > Etat de la négociation </ h2 >
2012-10-16 07:44:31 +00:00
< div class = " rowfiche " >
</ div >
< div class = " etire " >& nbsp ; </ div >
2013-06-19 08:24:49 +00:00
< h2 class = " bigger " > En l 'absence d' accord ou en cas d ' échec de la négociation </ h2 >
2012-10-16 07:44:31 +00:00
< div class = " rowfiche " >
< span class = " librfiche " > Qu ' avez - vous mis en place ? </ span >
2013-06-19 08:24:49 +00:00
< span class = " fieldrfiche " > un plan d ' actions concerté avec les IRP et délégués syndicaux < br /></ span >
2012-10-16 07:44:31 +00:00
</ div >
< div class = " etire " >& nbsp ; </ div >
< div class = " rowfiche " >
< span class = " librfiche " > Ce plan d ' actions porte sur :</ span >
2013-06-19 08:24:49 +00:00
< span class = " fieldrfiche " > état des lieux / diagnostic de la situation < br /> mise en place d<EFBFBD> un groupe projet / comité de pilotage ...< br /> processus de consultation et / ou consultation des acteurs < br /> formation ( cadres , salariés , IRP ... ) < br /></ span >
2012-10-16 07:44:31 +00:00
</ div >
*/
$tabInsert = $tabEnt [ $idfent_ ];
if ( preg_match ( '/<p><em>Fiche mise .+ jour le (.*)<\/em><\/p>/Uis' , $body , $results ))
$tabInsert [ 'dateMAJ' ] = WDate :: dateT ( 'd/m/Y' , 'Ymd' , $results [ 1 ]);
if ( preg_match ( '/">SIREN<\/acronym> \:<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis' , $body , $results ))
$tabInsert [ 'siren' ] = $results [ 1 ];
if ( preg_match ( '/<span class="librfiche">Avez\-vous engag.+ des n.+gociations \?<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis' , $body , $results ))
$tabInsert [ 'negotiations' ] = $results [ 1 ];
//else
$tabInsert [ 'debugHtml' ] = $body ;
if ( preg_match ( '/<span class="librfiche">Nbre de r.+unions tenues \:<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis' , $body , $results ))
$tabInsert [ 'nbreunions' ] = $results [ 1 ];
if ( preg_match ( '/<span class="librfiche">Avez vous sign.+ un accord \?<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis' , $body , $results ))
$tabInsert [ 'accordsigne' ] = $results [ 1 ];
if ( preg_match ( '/<span class="librfiche">Date de signature de l\'accord \:<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis' , $body , $results ))
{
$tabInsert [ 'accorddateTxt' ] = utf8_decode ( $results [ 1 ]);
$tabInsert [ 'accorddate' ] = WDate :: dateT ( 'dMY' , 'Ymd' , $tabInsert [ 'accorddateTxt' ]);
}
if ( preg_match ( '/<span class="librfiche">Type d\'accord \:<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis' , $body , $results ))
2013-06-19 08:24:49 +00:00
$tabInsert [ 'accordtype' ] = str_replace ( 'de m<> thodede contenu' , 'de m<> thode et de contenu' , strip_tags ( utf8_decode ( $results [ 1 ])));
2012-10-16 07:44:31 +00:00
if ( preg_match ( '/<span class="librfiche">Signataires de l\'accord \:<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis' , $body , $results ))
$tabInsert [ 'accordsignataires' ] = strip_tags ( utf8_decode ( $results [ 1 ]));
//if (preg_match('/<span class="librfiche"><span class="librfiche">Si accord de m.+thode, il porte sur \:<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis', $body, $results))
//if (preg_match('/<h2 class="bigger">Contenu de l\'accord<\/h2>(?:.*)<div class="rowfiche">(?:.*)<span class="librfiche">(.*)<\/span>(?:.*)<span class="fieldrfiche">(.*)<\/span>/Uis', $body, $results))
if ( preg_match ( '/<h2 class="bigger">Contenu de l\'accord<\/h2>(?:.*)<div class="rowfiche">(?:.*)<span class="librfiche">(.*)<\/div>/Uis' , $body , $results ))
$tabInsert [ 'accordinfo' ] = utf8_decode ( $results [ 1 ]);
if ( preg_match ( '/<h2 class="bigger">En l\'absence d\'accord ou en cas d.+chec de la n.+gociation<\/h2>(?:.*)<div class="rowfiche">(?:.*)<span class="librfiche">(.*)<hr\/>/Uis' , $body , $results ))
$tabInsert [ 'absenceEchec' ] = utf8_decode ( $results [ 1 ]);
$tabInsert [ 'dateInsert' ] = date ( 'YmdHis' );
if ( ! $iDb -> insert ( 'gouv_rps' , $tabInsert )) {
unset ( $tabInsert [ 'dateInsert' ]);
$ret = $iDb -> update ( 'gouv_rps' , $tabInsert , " idfent= $idfent " );
}
print_r ( $tabInsert );
//die();
/* 'popMunicipaleTxt' => trim ( strtr ( $results [ 1 ], array ( chr ( 160 ) => '' , ' ' => '' ))),
'popCptApartTxt' => trim ( strtr ( $results [ 2 ], array ( chr ( 160 ) => '' , ' ' => '' ))),
'popTotaleTxt' => trim ( strtr ( $results [ 3 ], array ( chr ( 160 ) => '' , ' ' => '' ))),
'popMunicipale' => trim ( strtr ( $results [ 1 ], array ( chr ( 160 ) => '' , ' ' => '' ))) * 1 ,
'popCptApart' => trim ( strtr ( $results [ 2 ], array ( chr ( 160 ) => '' , ' ' => '' ))) * 1 ,
'popTotale' => trim ( strtr ( $results [ 3 ], array ( chr ( 160 ) => '' , ' ' => '' ))) * 1 ,
'popAnnee' => 2007 ,
);
2013-06-19 08:24:49 +00:00
if ( preg_match ( '/<p><strong>R<> gion<\/strong> \:(.*)<\/p>/Uis' , $body , $results2 ))
2012-10-16 07:44:31 +00:00
$tabInsert [ 'region' ] = trim ( $results2 [ 1 ]);
2013-06-19 08:24:49 +00:00
if ( preg_match ( '/<p><strong>D<> partement<\/strong> \:(.*)<\/p>/Uis' , $body , $results2 ))
2012-10-16 07:44:31 +00:00
$tabInsert [ 'dept' ] = trim ( $results2 [ 1 ]);
if ( preg_match ( '/<p><strong>Arrondissement<\/strong> \:(.*)<\/p>/Uis' , $body , $results2 ))
$tabInsert [ 'arrond' ] = trim ( $results2 [ 1 ]);
if ( preg_match ( '/<p><strong>Canton<\/strong> \:(.*)<\/p>/Uis' , $body , $results2 ))
$tabInsert [ 'canton' ] = trim ( $results2 [ 1 ]);
if ( preg_match ( '/<p><strong>Commune<\/strong> \:(.*)<\/p>/Uis' , $body , $results2 ))
$tabInsert [ 'commune' ] = trim ( $results2 [ 1 ]);
$ret = $iDb -> insert ( 'insee_population' , $tabInsert );
// print_r($tabInsert);
echo date ( 'Y/m/d - H:i:s' ) . " - Commune " . $tabInsert [ 'commune' ] . ' : ' . $tabInsert [ 'popTotale' ] . " habitants ( $ret ) " . EOL ;
//die();*/
if ( $noTimer ) randsleep ( 1 , 2 );
else randsleep ( 7 , 21 );
}
die ();
?>