1512 lines
75 KiB
PHP
1512 lines
75 KiB
PHP
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
|
|
<?php
|
|
|
|
define('URL_BOURSE_HISTO', 'http://www.abcbourse.com/download/historiques.aspx?f=ex');
|
|
define('URL_BOURSE_COURS', 'http://www.abcbourse.com/download/telechargement_intraday.aspx');
|
|
define('URL_BOURSE_LISTE', 'http://www.abcbourse.com/download/libelles.aspx');
|
|
define('URL_BOURSE_IPO', 'https://europeanequities.nyx.com/fr/listings/ipo-showcase'); //?page=1
|
|
define('URL_BOURSE_ISIN_H', 'https://europeanequities.nyx.com/nyx_eu_listings/price_chart/download_historical?typefile=csv&layout=vertical');
|
|
define('URL_BOURSE_HISTO_NYX', 'https://europeanequities.nyx.com/fr/popup/data/download?ml=nyx_pd_stocks&cmd=default');
|
|
define('FILENAME_HISTO_NYX', '/tmp/getIsin-HistoNyx.csv');
|
|
define('FILENAME_BOURSE_HISTO', '/tmp/getIsin-HistoAbc.csv');
|
|
|
|
/*
|
|
21:44:21.926[751ms][total 751ms] État: 200[OK]
|
|
POST http://www.abcbourse.com/download/historiques.aspx Indicateurs chargement[LOAD_DOCUMENT_URI LOAD_INITIAL_DOCUMENT_URI ] Taille contenu[43678] Type Mime[text/plain]
|
|
En-têtes requête:
|
|
Host[www.abcbourse.com]
|
|
User-Agent[Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1]
|
|
Accept[text/html,application/xhtml+xml,application/xml;q=0.9,
|
|
Accept-Language[fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3]
|
|
Accept-Encoding[gzip, deflate]
|
|
Accept-Charset[ISO-8859-1,utf-8;q=0.7,*;q=0.7]
|
|
Connection[keep-alive]
|
|
Referer[http://www.abcbourse.com/download/historiques.aspx]
|
|
Cookie[__utma=107798994.115733841.1327178479.1327178479.1327178479.1; __utmb=107798994.8.10.1327178479; __utmc=107798994; __utmz=107798994.1327178479.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); ASP.NET_SessionId=f54wyf45ysddkgf4mjbqftey]
|
|
Données POST:
|
|
ctl00_BodyABC_ToolkitScriptManager1_HiddenField[%3B%3BAjaxControlToolkit%2C+Version%3D3.0.20229.20843%2C+Culture%3Dneutral%2C+PublicKeyToken%3D28f01b0e84b6d53e%3Afr-FR%3A3b7d1b28-161f-426a-ab77-b345f2c428f5%3A865923e8%3A9b7907bc%3A411fea1c%3Ae7c87f07%3A91bd373d%3Abbfda34c%3A30a78ec5%3A9349f837%3Ad4245214%3A8e72a662%3Aacd642d2%3A596d588c%3A77c58d20%3A14b56adc%3A269a19ae]
|
|
__EVENTTARGET[]
|
|
__EVENTARGUMENT[]
|
|
__VIEWSTATE[%2FwEPDwUJMjUzMjM0NTI3ZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WJwUWY3RsMDAkQm9keUFCQyRldXJvbGlzdAUcY3RsMDAkQm9keUFCQyRhY3Rpb25zaW5kaWNlcwUaY3RsMDAkQm9keUFCQyRhY3Rpb25zaW5kdXMFFWN0bDAwJEJvZHlBQkMkY29tcGxldAUbY3RsMDAkQm9keUFCQyRjb21wbGV0bm93YXJyBRJjdGwwMCRCb2R5QUJDJHNyZHAFGGN0bDAwJEJvZHlBQkMkaW5kaWNlc0ZScAUYY3RsMDAkQm9keUFCQyRldXJvbGlzdGFwBRhjdGwwMCRCb2R5QUJDJGV1cm9saXN0YnAFGGN0bDAwJEJvZHlBQkMkZXVyb2xpc3RjcAUZY3RsMDAkQm9keUFCQyRldXJvbGlzdHplcAUUY3RsMDAkQm9keUFCQyRhbHRlcnAFEGN0bDAwJEJvZHlBQkMkbWwFFGN0bDAwJEJvZHlBQkMkdHJhY2twBRFjdGwwMCRCb2R5QUJDJGJzcAUTY3RsMDAkQm9keUFCQyRvYmwycAUSY3RsMDAkQm9keUFCQyRvYmxwBRZjdGwwMCRCb2R5QUJDJHdhcnJhbnRzBRJjdGwwMCRCb2R5QUJDJGZjcHAFFWN0bDAwJEJvZHlBQkMkeGNhYzQwcAUWY3RsMDAkQm9keUFCQyR4c2JmMTIwcAUVY3RsMDAkQm9keUFCQyR4Y2FjYXRwBRZjdGwwMCRCb2R5QUJDJHhjYWNuMjBwBRhjdGwwMCRCb2R5QUJDJHhjYWNzbWFsbHAFFWN0bDAwJEJvZHlBQkMkeGNhYzYwcAUWY3RsMDAkQm9keUFCQyR4Y2FjbDYwcAUVY3RsMDAkQm9keUFCQyR4Y2FjbXNwBRVjdGwwMCRCb2R5QUJDJHhiZWwyMGcFFWN0bDAwJEJvZHlBQkMkeGFleDI1bgURY3RsMDAkQm9keUFCQyRkanUFEmN0bDAwJEJvZHlBQkMkbmFzdQUUY3RsMDAkQm9keUFCQyRzcDUwMHUFEmN0bDAwJEJvZHlBQkMkdXNhdQUSY3RsMDAkQm9keUFCQyRiZWxnBRNjdGwwMCRCb2R5QUJDJGhvbGxuBRVjdGwwMCRCb2R5QUJDJGxpc2JvYWwFEmN0bDAwJEJvZHlBQkMkZGV2cAUVY3RsMDAkQm9keUFCQyRvbmVTaWNvBRNjdGwwMCRCb2R5QUJDJGNiWWVz%2BsS2JGgdTPMzT67Kk4j41fKYkb0%3D]
|
|
__EVENTVALIDATION[%2FwEWPgLwo8iJDAKPgp47AuX3t%2B0NAoLSprgMAr7jqP8KAu7P4%2F0BAqKE4sMEAovUvJkOAoyS8LkNArPy16cOAs7D2KsOAre767oNAonG%2FcEHAriKpIIJAtPzwZcDAufBpr8OApeMiP0GAoSYiOsEAqajl%2FkIAs%2Ft68QPAouLt8YNAsLoj7MCAvTZqtILAuPI9KICApeY0uUNArGJ%2BZcLAqDEhNQNAvXt%2B%2BwMApma3OYLAs3qjZACAr%2Bb8NUFAuSyzpoDAvrGrrwMAvPGhsMEAp6bvJgIAo7%2F6cIPAoiY%2F34ClfG83AIC6%2B3nrgwC%2FPC9%2BgcCnOOzhwECn5vYgwgCmJXlpQ0C64nUxAoCvKXGgggCusuh2g8Cusuh2g8Czcuh2g8CyMuh2g8Cq8uh2g8CyMuh2g8Cusuh2g8CsMuh2g8CvMuh2g8CsMuh2g8Cusuh2g8Cusuh2g8CqtSqawKW8NTsBQKe5dnRCwKN37s5AvfF2O4MZz3S6Hh5%2B8oV06LsCyVsEdDTkuI%3D]
|
|
ctl00%24txtAutoComplete[]
|
|
ctl00%24BodyABC%24strDateDeb[20%2F01%2F2012]
|
|
ctl00%24BodyABC%24strDateFin[20%2F01%2F2012]
|
|
ctl00%24BodyABC%24complet[on]
|
|
ctl00%24BodyABC%24txtOneSico[]
|
|
ctl00%24BodyABC%24Button1[T%C3%A9l%C3%A9charger]
|
|
ctl00%24BodyABC%24dlFormat[w]
|
|
ctl00%24BodyABC%24listFormat[isin]
|
|
En-têtes réponse:
|
|
Cache-Control[private]
|
|
Content-Type[text/plain; charset=utf-8]
|
|
Content-Encoding[gzip]
|
|
Vary[Accept-Encoding]
|
|
Server[Microsoft-IIS/7.5]
|
|
Content-Disposition[attachment; filename=Cotations20120120.txt]
|
|
X-AspNet-Version[2.0.50727]
|
|
X-Powered-By[ASP.NET]
|
|
Date[Sat, 21 Jan 2012 20:44:26 GMT]
|
|
Content-Length[43678]
|
|
|
|
|
|
*/
|
|
include_once(FWK_PATH.'common/chiffres.php');
|
|
include_once(FWK_PATH.'common/dates.php');
|
|
include_once(INCLUDE_PATH.'bodacc/classMBodacc.php');
|
|
include_once(INCLUDE_PATH.'insee/classMInsee.php');
|
|
include_once(INCLUDE_PATH.'partenaires/classMBourse.php');
|
|
include_once(FWK_PATH.'mail/sendMail.php');
|
|
|
|
global $tempsMinEntreRequetes;
|
|
global $tempsMaxEntreRequetes;
|
|
|
|
$tempsMinEntreRequetes=5;
|
|
$tempsMaxEntreRequetes=20;
|
|
|
|
$tabJour=array(0=>'Dim', 1=>'Lun', 2=>'Mar', 3=>'Mer', 4=>'Jeu', 5=>'Ven', 6=>'Sam');
|
|
|
|
function getNextDate($dateCour, $nbJours=7) {
|
|
$nextDate=date('Ymd', mktime(0, 0, 0, WDate::dateT('Ymd','m', $dateCour), WDate::dateT('Ymd','d', $dateCour)+$nbJours, WDate::dateT('Ymd','Y', $dateCour)));
|
|
return $nextDate;
|
|
}
|
|
|
|
function getEasyBourse() {
|
|
if (!file_exists('/tmp/easybourse.txt') || date('Ymd', filectime('/tmp/easybourse.txt'))<>date('Ymd')) {
|
|
echo date('Y/m/d - H:i:s') ." - Récupération des informations sur les entreprises côtées...".EOL;
|
|
$url='http://www.easybourse.com/Tableaux/Societe/InsereSocieteBDD.php';
|
|
$page=getUrl($url);
|
|
$body=$page['body'];
|
|
file_put_contents('/tmp/easybourse.txt',$body);
|
|
echo date('Y/m/d - H:i:s') ." - Fin de la récupération des informations.".EOL;
|
|
} else
|
|
$body=file_get_contents('/tmp/easybourse.txt');
|
|
|
|
echo date('Y/m/d - H:i:s') ." - Conversion des informations en SQL...".EOL;
|
|
$body2=strtr($body, array( '<br/>'=>"\n",
|
|
'<br>'=>"\n",
|
|
/*'***********************************************************************************************'=>''*/));
|
|
$body2=preg_replace('/<b>.*<\/b>/Uis', '', $body2);
|
|
$body2=preg_replace('/\*{95,95}/Uis', '', $body2);
|
|
$body2=preg_replace('/^\D\D.{10,10}\.php/mUi', '', $body2);
|
|
|
|
$body2=preg_replace('/^\d{1,5}/mUi', '', $body2);
|
|
$body2=preg_replace('/^\(\d{1,5}\)/mUi', '', $body2);
|
|
$body2=preg_replace('/^\d/mUi', '', $body2);
|
|
|
|
$body2=preg_replace('/\)$/mUi', ');', $body2);
|
|
|
|
file_put_contents('/tmp/easybourse.sql',$body2);
|
|
|
|
echo date('Y/m/d - H:i:s') ." - Génération des tables...".EOL;
|
|
$query='DROP TABLE IF EXISTS `elenco_indices`;
|
|
CREATE TABLE `elenco_indices` (
|
|
`isin` char(12) NOT NULL,
|
|
`updated` datetime NOT NULL,
|
|
`CompartimentA` tinyint(1) NOT NULL,
|
|
`CompartimentB` tinyint(1) NOT NULL,
|
|
`CompartimentC` tinyint(1) NOT NULL,
|
|
`CompartimentSpecial` tinyint(1) NOT NULL,
|
|
`MarcheLibre` tinyint(1) NOT NULL,
|
|
`Alternext` tinyint(1) NOT NULL,
|
|
`EurolistZoneEuro` tinyint(1) NOT NULL,
|
|
`EurolistHorsZoneEuro` tinyint(1) NOT NULL,
|
|
`CACAllShares` tinyint(1) NOT NULL,
|
|
`CAC40` tinyint(1) NOT NULL,
|
|
`CACMIDSMALL190` tinyint(1) NOT NULL,
|
|
`CACMID100` tinyint(1) NOT NULL,
|
|
`CACNEXT20` tinyint(1) NOT NULL,
|
|
`CACSMALL90` tinyint(1) NOT NULL,
|
|
`CACIT` tinyint(1) NOT NULL,
|
|
`CACIT20` tinyint(1) NOT NULL,
|
|
`SBF80` tinyint(1) NOT NULL,
|
|
`SBF120` tinyint(1) NOT NULL,
|
|
`SBF250` tinyint(1) NOT NULL,
|
|
`AlternextAllShare` tinyint(1) NOT NULL,
|
|
`SRD` tinyint(1) NOT NULL,
|
|
`PEA` tinyint(1) NOT NULL,
|
|
PRIMARY KEY (`isin`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
|
|
|
DROP TABLE IF EXISTS `societe_actionnaire`;
|
|
CREATE TABLE `societe_actionnaire` (
|
|
`updated` datetime NOT NULL,
|
|
`isin` char(12) NOT NULL,
|
|
`id_cofisem` bigint(20) NOT NULL,
|
|
`type` char(1) NOT NULL,
|
|
`genre` char(30) NOT NULL,
|
|
`particule` char(5) NOT NULL,
|
|
`nom` varchar(80) NOT NULL,
|
|
`prenom` varchar(80) NOT NULL,
|
|
`compagnie` varchar(255) NOT NULL,
|
|
`sign` char(1) NOT NULL,
|
|
`interet` float(5,2) NOT NULL
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
|
|
|
|
|
DROP TABLE IF EXISTS `societe_bilan`;
|
|
CREATE TABLE `societe_bilan` (
|
|
`updated` datetime NOT NULL,
|
|
`idLigne` bigint(20) NOT NULL,
|
|
`isin` char(12) NOT NULL,
|
|
`dateAV` date NOT NULL,
|
|
`devise` char(3) NOT NULL,
|
|
`unites` char(10) NOT NULL,
|
|
`code` smallint(4) unsigned zerofill NOT NULL,
|
|
`libelle` varchar(80) NOT NULL,
|
|
`montant` bigint(20) NOT NULL
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
|
|
|
DROP TABLE IF EXISTS `societe_compte_resultat`;
|
|
CREATE TABLE `societe_compte_resultat` (
|
|
`updated` datetime NOT NULL,
|
|
`idLigne` bigint(20) NOT NULL,
|
|
`isin` char(12) NOT NULL,
|
|
`dateAV` date NOT NULL,
|
|
`devise` char(3) NOT NULL,
|
|
`unites` char(10) NOT NULL,
|
|
`code` smallint(4) unsigned zerofill NOT NULL,
|
|
`libelle` varchar(80) NOT NULL,
|
|
`montant` bigint(20) NOT NULL
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
|
|
|
DROP TABLE IF EXISTS `societe_contact`;
|
|
CREATE TABLE `societe_contact` (
|
|
`updated` datetime NOT NULL,
|
|
`isin` char(12) NOT NULL,
|
|
`id_cofisem` bigint(20) NOT NULL,
|
|
`genre` char(15) NOT NULL,
|
|
`nom` varchar(80) NOT NULL,
|
|
`prenom` varchar(80) NOT NULL,
|
|
`fonction` varchar(80) NOT NULL,
|
|
`compagnie` varchar(80) NOT NULL
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
|
|
|
DROP TABLE IF EXISTS `societe_identification`;
|
|
CREATE TABLE `societe_identification` (
|
|
`isin` char(12) NOT NULL,
|
|
`updated` datetime NOT NULL,
|
|
`nomvaleur` varchar(255) NOT NULL,
|
|
`adresse` varchar(255) NOT NULL,
|
|
`zip` char(30) NOT NULL,
|
|
`ville` varchar(50) NOT NULL,
|
|
`pays` varchar(50) NOT NULL,
|
|
`telephone` varchar(20) NOT NULL,
|
|
`fax` varchar(20) NOT NULL,
|
|
`site_internet` varchar(100) NOT NULL,
|
|
`secteur` varchar(80) NOT NULL,
|
|
`dernier_rdv_actionnaire` varchar(30) NOT NULL,
|
|
`indice_principal` varchar(80) NOT NULL,
|
|
`indice_autres` varchar(80) NOT NULL,
|
|
`srd` char(3) NOT NULL,
|
|
`marche` varchar(40) NOT NULL,
|
|
`place_cotation` varchar(45) NOT NULL,
|
|
`description` longtext NOT NULL,
|
|
PRIMARY KEY (`isin`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
|
|
|
DROP TABLE IF EXISTS `societe_ratio`;
|
|
CREATE TABLE `societe_ratio` (
|
|
`updated` datetime NOT NULL,
|
|
`idLigne` bigint(20) NOT NULL,
|
|
`isin` char(12) NOT NULL,
|
|
`dateAV` date NOT NULL,
|
|
`code` smallint(4) unsigned zerofill NOT NULL,
|
|
`libelle` varchar(80) NOT NULL,
|
|
`montant` bigint(20) NOT NULL
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
|
|
|
DROP TABLE IF EXISTS `societe_resultat_trim`;
|
|
CREATE TABLE `societe_resultat_trim` (
|
|
`updated` datetime NOT NULL,
|
|
`idLigne` bigint(20) NOT NULL,
|
|
`isin` char(12) NOT NULL,
|
|
`dateAV` date NOT NULL,
|
|
`devise` char(3) NOT NULL,
|
|
`unites` char(10) NOT NULL,
|
|
`code` smallint(4) unsigned zerofill NOT NULL,
|
|
`libelle` varchar(80) NOT NULL,
|
|
`montant` bigint(20) NOT NULL
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
|
|
file_put_contents('/tmp/easybourseini.sql', $query);
|
|
exec("mysql -pbzh4231* -h 192.168.3.22 sdv1 < /tmp/easybourseini.sql");
|
|
|
|
echo date('Y/m/d - H:i:s') ." - Chargement des tables...".EOL;
|
|
exec("mysql -pbzh4231* -h 192.168.3.22 sdv1 < /tmp/easybourse.sql");
|
|
|
|
echo date('Y/m/d - H:i:s') ." - Fin du chargement des tables...".EOL;
|
|
|
|
return true;
|
|
}
|
|
|
|
function getInfosIsin($isin) {
|
|
global $tempsMinEntreRequetes;
|
|
global $tempsMaxEntreRequetes;
|
|
|
|
$url='http://www.boursica.com/ficheaction.php1/liste/'.$isin;
|
|
$referer= 'http://www.boursica.com/haut0.php?moncontenu=%2Fficheaction.php1%2Fliste%2F'.$isin.
|
|
'&scr=1440x900x32&flash=1&java=1&vbscript=0&pdf=1&dall=0&mime=1&ver=&cookieok=1&cpu=&sys=Win32';
|
|
$page=getUrl($url, ''/*$cookie*/, ''/*$postData*/, $referer);
|
|
$body=$page['body'];
|
|
//print_r($page);
|
|
//die();
|
|
$tabInfo=array();
|
|
|
|
$tabInfo['raisonSociale']=trim(htm2txt(@getTextInHtml($body, '<font face="Arial Black" size="4">', 'size="4">', '</font>')));
|
|
if (preg_match('/src=\'\/logo_ste\.php\?(.*)\'>"\);<\/script>/i', $body, $matches)) {
|
|
$logo=getUrl('http://www.boursica.com/logo_ste.php?'.$matches[1], '', '', $url);
|
|
//http://www.boursica.com/logo_ste.php?122/FR0010106039/logo417
|
|
$fp=fopen("/home/data/logos/isin/$isin.gif", 'a');
|
|
fwrite($fp, $logo['body']);
|
|
fclose($fp);
|
|
$tabInfo['logo']='O';
|
|
} else {
|
|
$logo=getUrl("http://www.stockproinfo.com//cofisemhebergement/logos/$isin.jpg");
|
|
if ($logo['code']==200) {
|
|
$fp=fopen("/home/data/logos/isin/$isin.jpg", 'a');
|
|
fwrite($fp, $logo['body']);
|
|
fclose($fp);
|
|
$tabInfo['logo']='O';
|
|
} else
|
|
$tabInfo['logo']='N';
|
|
}
|
|
$tabInfo['code_isin']=$isin;//@getTextInHtml($body, '<tr><td>Code ISIN : ', '<b>', '</b>');
|
|
$tabInfo['code_mnemo']=htm2txt(@getTextInHtml($body, '<nobr>Mnémonique', '<b>', '</b>'));
|
|
$tabInfo['code_ric']=htm2txt(@getTextInHtml($body, '<nobr>Reuter', '<b>', '</b>'));
|
|
$tabInfo['code_bloomberg']=htm2txt(@getTextInHtml($body, '<nobr>Bloomberg', '<b>', '</b>'));
|
|
$tabInfo['code_datastream']=htm2txt(@getTextInHtml($body, '<nobr>Datastream', '<b>', '</b>'));
|
|
$tabInfo['code_sicovam']=htm2txt(@getTextInHtml($body, 'SICOVAM (périmé) : ', '<b>', '</b>'));
|
|
|
|
//$tabInfo['indices']=@getTextInHtml($body, 'Indices :', '<b>', '</b>');
|
|
$tabInfo['marche']=htm2txt(@getTextInHtml($body, 'Marché : ', '<b>', '</b>'));
|
|
//$tabInfo['CapiB']=htm2txt(@getTextInHtml($body, 'Capitalisation Boursière : ', '<b>', '</b>'));
|
|
$tabInfo['eligibleSRD']=trim(substr(strtoupper(htm2txt(@getTextInHtml($body, 'Eligible SRD', '<b>', '</b>'))),0,1));
|
|
$tabInfo['eligiblePEA']=trim(substr(strtoupper(htm2txt(@getTextInHtml($body, ' PEA : ', '<b>', '</b>'))),0,1));
|
|
|
|
if (preg_match('/Activité : <b>(.*)<\/b>/i', $body, $matches))
|
|
$tabInfo['activite']=$matches[1];
|
|
else $tabInfo['activite']='';
|
|
|
|
$tabInfo['adresse']=@getTextInHtml($body, '</td></tr><tr><td>Adresse', ' : ', '</td></tr>');
|
|
$tabInfo['fax2']=@getTextInHtml($body, '<br>Télécopie ', ': ', '</td></tr>');
|
|
if (trim($tabInfo['fax2']<>''))
|
|
$tabInfo['tel2']=@getTextInHtml($body, '</td></tr><tr><td nowrap>Téléphone', ' : ', '<br>');
|
|
else
|
|
$tabInfo['tel2']=@getTextInHtml($body, '</td></tr><tr><td nowrap>Téléphone', ' : ', '</td></tr>');
|
|
$tabInfo['web']=htm2txt(@getTextInHtml($body, 'Site Internet : <a href=', "target='_blank'>", '</td>'));
|
|
$tabInfo['mail']=htm2txt(@getTextInHtml($body, 'Email : <a onclick=\'javascript:document.location="', 'mailto:', '"\'>'));
|
|
$tabInfo['dateIntroduction']=@getTextInHtml($body, 'Date d\'introduction en bourse', ' : ', '</td></tr>');
|
|
$tabInfo['description']=htm2txt(@getTextInHtml($body, '<b>Description de la société ou de l\'activité :</b>', '</td></tr>', '</table>'));
|
|
// DEB info debug
|
|
//$tabInfo['information']=htm2txt(@getTextInHtml($body, '<b>Informations sur la société :</b></td>', '</tr>', '<a name="depeches"></a>'));
|
|
//$tabInfo['codes']=htm2txt(@getTextInHtml($body, '<font face="Arial Black" size="4">', 'size="4">', '<td valign="top" nowrap>'));
|
|
// FIN infos debug
|
|
|
|
//$url='http://www.boursorama.com/profil/resume_societe.phtml?symbole=1rP'.$tabInfo['cod_mnemo'];
|
|
|
|
/*
|
|
15:22:46.047[110ms][total 110ms] État: 302[Found]
|
|
GET
|
|
|
|
Referer[]
|
|
Cookie[OBJECT_BOURSORAMA=0; TestIfCookieP=ok; pbw=%24b%3D203%3B%24o%3D1%3B%24c%3D49%3B%3B%24sh%3D3%3B%24sw%3D5; pid=8867356407134676522; __utma=88976520.767099551.1252359392.1252497130.1252502516.4; __utmz=88976520.1252502516.4.4.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=boursorama; __utma=88976520.767099551.1252359392.1252497130.1252502516.4; __utmv=88976520.WEB-VISITOR; __utmv=88976520.WEB-VISITOR; pbwmaj=y; PHPSESSIONID=9dcfbab96bda3825fa96bf19601fbdc2; perso=eAHztzI0s1IKSC0qzs%2FLS8zJLE4syczPU7IysaoutjK0UipRsk60MrCqrgXzCpSsM60MTQwNDM3NjcyMrcGCOShKkkFKzAwMDAytawEj9Bp0; vs=177=3518844&609=3518754; __utmc=88976520; __utmc=88976520; STORAGE_COOKIE=eJxNjEEKgCAQRe8y%2ByCnjBiXHSRKEwLLKF1EefdUgtrM%2FHn%2FMeoeCOk64gDpQAzE0sUJlC56CWImhhx5iU2NIvybV2UlgfbGSH84uySc%2F7XZc%2Bc2dSCiRYB5Vx%2B3fh%2BnBGsCM68xhhAeBUwrag%3D%3D; __utmb=88976520.0.10.1252502516; __utmb=88976520.1.10.1252502516]
|
|
|
|
En-têtes réponse:
|
|
Date[Wed, 09 Sep 2009 13:25:05 GMT]
|
|
Server[Apache]
|
|
Vary[Accept-Encoding,Use]
|
|
x-ua-compatible[IE=EmulateIE7]
|
|
Cache-Control[no-store, no-cache, must-revalidate, post-check=0, pre-check=0]
|
|
Pragma[no-cache]
|
|
Expires[Thu, 19 Nov 1981 08:52:00 GMT]
|
|
Location[]
|
|
Keep-Alive[timeout=3, max=100]
|
|
Connection[Keep-Alive]
|
|
Transfer-Encoding[chunked]
|
|
Content-Type[text/html; charset=ISO-8859-1]
|
|
*/
|
|
// $url='http://www.boursorama.com/recherche/recherche.phtml?query=&searchType=rapide&searchCategorie=Tous&searchChoixBourse=pays%3D33
|
|
$url='http://www.boursorama.com/recherche/index.phtml?search%5Bquery%5D='.$isin.'&search%5Btype%5D=rapide&search%5Bcategorie%5D=STK&search%5Bbourse%5D=country%3A33';
|
|
$referer='http://www.boursorama.com/recherche/index.phtml?search[bourse]=&search[bourse]=&search[categorie]=';
|
|
$page=getUrl($url, ''/*$cookie*/, ''/*$postData*/, $referer);
|
|
$referer=$url;
|
|
if($page['code']<>302) return $tabInfo;
|
|
$url='http://www.boursorama.com'.trim($page['header']['Location']); // => /cours.phtml?symbole=1rPEDL
|
|
// => /cours.phtml?symbole=1rPMLONE-OTC&search%5Bquery%5D=FR0010106039
|
|
// echo 'Symbole='.$page['header']['Location'].EOL;
|
|
if (preg_match('/symbole=(.*)&/Ui', $url, $matches)) {
|
|
$tabInfo['code_boursorama']=trim($matches[1]);
|
|
if ($tabInfo['code_mnemo']=='')
|
|
$tabInfo['code_mnemo']=preg_replace('/\-.*$/U', '',preg_replace('/^1rP/','',$tabInfo['code_boursorama']));// 1rP MLCEC -OTC
|
|
} else
|
|
$tabInfo['code_boursorama']='';
|
|
|
|
// Cours actuel
|
|
$page=getUrl($url, ''/*$cookie*/, ''/*$postData*/, $referer);
|
|
$body=$page['body'];
|
|
$cookie=@$page['header']['Set-Cookie'];
|
|
$referer=$url;
|
|
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$url='http://www.boursorama.com/profil/resume_societe.phtml?symbole='.urlencode($tabInfo['code_boursorama']);
|
|
//echo('Url='.$url.EOL.'Cookie='.$cookie.EOL.'Referer='.$referer.EOL);
|
|
|
|
$page=getUrl($url, $cookie, ''/*$postData*/, $referer);
|
|
$referer=$url;
|
|
$body=$page['body'];
|
|
|
|
//$tabInfo['nom2']=htm2txt(@getTextInHtml($body, '<TD colspan=2 align=left><font size="+1">', '<b>', '</b>'));
|
|
//$tabInfo['cod_mnemo2']=htm2txt(@getTextInHtml($body, '<td align=left>'.$isin, ' - ', '</td>'));
|
|
$tabInfo['nombreTitres']=str_replace(' ','',htm2txt(@getTextInHtml($body, '<div class="list_label">Nombre de titres : </div>', '<div style="float:left;">', '</div>')));
|
|
|
|
$tabInfo['secteur']=htm2txt(strip_tags(@getTextInHtml($body, '<div class="list_label">Secteur d\'activité : </div>', '<div style="float:left;">', '</div>')));
|
|
$tabInfo['marche']=htm2txt(@getTextInHtml($body, '<div class="list_label">Marché : </div>', '<div style="float:left;">', '</div>'));
|
|
$tabInfo['placeCotation']=htm2txt(@getTextInHtml($body, '<div class="list_label">Place de cotation : </div>', '<div style="float:left;">', '</div>'));
|
|
$tmp=htm2txt(@getTextInHtml($body, '<div class="list_label">Eligibilité PEA / SRD : </div>', '<div style="float:left;">', '</div>'));
|
|
$tmp=explode('/', $tmp);
|
|
$tabInfo['eligibleSRD']=substr(strtoupper(trim($tmp[1])),0,1);
|
|
if ($tabInfo['eligiblePEA']=='')
|
|
$tabInfo['eligiblePEA']=substr(strtoupper(trim($tmp[0])),0,1);
|
|
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$url='http://www.boursorama.com/profil/profil.phtml?symbole='.urlencode($tabInfo['code_boursorama']);
|
|
//http://www.boursorama.com/profil/profil.phtml?symbole=1rPUG
|
|
$page=getUrl($url, $cookie, '', $referer);
|
|
$referer=$url;
|
|
$body=$page['body'];
|
|
|
|
if ($tabInfo['raisonSociale']=='') $tabInfo['raisonSociale']=trim(htm2txt(@getTextInHtml($body, '<div class="list_label">Raison sociale</div>', '<div style="float:left;">', '</div>')));
|
|
if ($tabInfo['adresse']=='')$tabInfo['adresse'] =trim(htm2txt(@getTextInHtml($body, '<div class="list_label">Raison sociale</div>', '<div style="float:left;">', '</div>')));
|
|
if ($tabInfo['web']=='') $tabInfo['web'] =trim(htm2txt(@getTextInHtml($body, '<div class="list_label">Site Web</div>', '<div style="float:left;">', '</div>')));
|
|
|
|
$tabInfo['activiteDet']=htm2txt(@getTextInHtml($body, '<div class="body news">', '<p class="txt02">', '</div>'));
|
|
$tabInfo['effectif']=str_replace(' ','',htm2txt(@getTextInHtml($body, '<p class="txt02">Effectif', ' : ', '</p>')));
|
|
$tabInfo['tel1'] =trim(htm2txt(@getTextInHtml($body, '<div class="list_label">Téléphone</div>', '<div style="float:left;">', '</div>')));
|
|
$tabInfo['fax1'] =trim(htm2txt(@getTextInHtml($body, '<div class="list_label">Télécopie</div>', '<div style="float:left;">', '</div>')));
|
|
|
|
// $tabInfo['dateDerAG']=htm2txt(@getTextInHtml($body, '<FONT FACE="ms sans serif,verdana,arial" SIZE=2>Date de la dernière assemblée générale', ' : ', '</TD></TR>'));
|
|
|
|
//$tabInfo['nom3']=htm2txt(@getTextInHtml($body, '<TD><FONT FACE="ms sans serif,verdana,arial" SIZE=2>Raison sociale', '</TD>', '</TR>'));
|
|
/*
|
|
$tmp=@getTextInHtml($body, '<!-- DIRIGEANTS -->', '<TR BGCOLOR="#FFFFFF">', '<!-- /DIRIGEANTS -->');
|
|
$tabTmp=explode('<TR BGCOLOR="#FFFFFF">', $tmp);
|
|
$tabDir=array();
|
|
foreach ($tabTmp as $i=>$dir) {
|
|
$tmp=explode('</TD>', $dir);
|
|
$tabDir[$i]=array('Fonction'=>htm2txt($tmp[0]), 'NomPrenom'=>htm2txt($tmp[1]));
|
|
}
|
|
$tabInfo['dirigeants']=$tabDir;
|
|
|
|
$tmp=@getTextInHtml($body, '<!-- ACTIONNARIAT -->', '<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>', '</TABLE>');
|
|
$tabTmp=explode('</TR>', $tmp);
|
|
$nb=count($tabTmp)-1;
|
|
$tabDir=array();
|
|
for ($i=0; $i<$nb; $i++) {
|
|
$tmp=explode('</TD>', $tabTmp[$i]);
|
|
$tabDir[$i]=array('Nom'=>htm2txt($tmp[0]), 'Pct'=>htm2txt($tmp[1]));
|
|
}
|
|
$tabInfo['actionnaires']=$tabDir;
|
|
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$url='http://www.boursorama.com/profil/profil_finance.phtml?symbole='.urlencode($tabInfo['code_boursorama']);
|
|
//echo('Url='.$url.EOL.'Cookie='.$cookie.EOL.'Referer='.$referer.EOL);
|
|
//die();
|
|
$page=getUrl($url, $cookie, ''$postData, $referer);
|
|
$referer=$url;
|
|
$body=$page['body'];
|
|
|
|
$tmp=@getTextInHtml($body, '<!-- DONNEES TRIMESTRIELLES -->', '<TR CLASS="entetetab">', '</table>');
|
|
$tabTmp=explode('<TD NOWRAP ALIGN="LEFT"> ', $tmp);
|
|
//die(print_r($tabTmp));
|
|
|
|
$tabTrim=array();
|
|
foreach ($tabTmp as $i=>$dir) {
|
|
$tmp=explode('</TD>', $dir);
|
|
if ($i==0)
|
|
foreach ($tmp as $k=>$tmp2)
|
|
$tabA[$k]=htm2txt($tmp2);
|
|
else
|
|
foreach ($tmp as $k=>$tmp2)
|
|
if (isset($tabA[$k]) && trim($tabA[$k])<>'')
|
|
$tabTrim[$tabA[$k]][$i-1]=str_replace(' ','', htm2txt($tmp2));
|
|
}
|
|
/* 0. 1er Trimestre
|
|
1. 2è Trimestre
|
|
2. 3è Trimestre
|
|
3. 4è Trimestre
|
|
4. 1er Semestre
|
|
5. Annuel
|
|
*
|
|
$tabInfo['chiffresTrim']=$tabTrim;
|
|
*/
|
|
return $tabInfo;
|
|
}
|
|
|
|
$iDb=new WDB();
|
|
$iDb2=new WDB('sdv1');
|
|
//$iInsee=new MInsee();
|
|
$iBourse=new MBourse();
|
|
|
|
set_time_limit(0);
|
|
|
|
$allIsin=$dernierCour=$finSeance=$dateDebut=$dateFin=$dateF=$checkIsin=$isin=$dateCour=$easyBourse=$marcheNew=$marcheRad=$getIPO=$isinHisto=false;
|
|
$strMailInfo='';
|
|
|
|
$strInfoProg='Usage : '.basename($argv[0]). " [OPTION]
|
|
Recupère les informations boursières.
|
|
|
|
Sans aucun paramètre, récupère les dernières valeurs des cotations en cours.
|
|
Sinon:
|
|
-d:JJ/MM/AAAA Date de début de cotation
|
|
-f:JJ/MM/AAAA Date de fin de cotation
|
|
-l Récupère les dernières valeurs des cotations en cours (1)
|
|
-s Récupère les valeurs des cotations à la fin de la dernière séance
|
|
-n:X Intervalle MIN en secondes entre les requêtes (défaut=$tempsMinEntreRequetes)
|
|
-i:X \" MAX \" \" \" \" \" (défaut=$tempsMaxEntreRequetes)
|
|
-a Mise à jour de toutes les autres informations d'un code ISIN
|
|
-n(:XXXX) Mise à jour des nouvelles introductions des marchés (XXXX : année optionnelle)
|
|
-r Mise à jour des radiations des marchés
|
|
-c:FR0000031577 Mise à jour uniquement des informations du code ISIN donné
|
|
-v Vérifie que tous les codes ISIN côtés sont bien en base de référence (SIREN, dates, etc...)
|
|
-e Mise à jour des référentiels Cofisem via Easybourse
|
|
-p Récupère les IPO (Introductions en bourse) (2)
|
|
-h:FR0000031577 Récupère l'historique des cours pour un code ISIN donné
|
|
|
|
(1) Action par défaut
|
|
(2) Non fonctionnel
|
|
";
|
|
|
|
$argv=$_SERVER['argv'];
|
|
if ($_SERVER['argc']==1) $dernierCour=true;
|
|
else {
|
|
for ($i=1; isset($argv[$i]); $i++) {
|
|
if (substr($argv[$i],0,1)=='-') {
|
|
switch (substr($argv[$i],1,1)) {
|
|
case 'd': $dateDebut=substr($argv[$i],3,10);
|
|
$dateDeb=WDate::dateT('d/m/Y', 'Ymd', $dateDebut); break;
|
|
case 'f': $dateFin=substr($argv[$i],3,10);
|
|
$dateF=WDate::dateT('d/m/Y', 'Ymd', $dateFin); break;
|
|
case 'n': $tempsMinEntreRequetes=trim(substr($argv[$i],3))*1;
|
|
if ($tempsMinEntreRequetes<0) $tempsMinEntreRequetes=0; break;
|
|
case 'i': $tempsMaxEntreRequetes=trim(substr($argv[$i],3))*1;
|
|
if ($tempsMaxEntreRequetes<5) $tempsMaxEntreRequetes=2; break;
|
|
case 'n': $marcheNew=true; break;
|
|
case 'r': $marcheRad=true; break;
|
|
case 'l': $dernierCour=true; break;
|
|
case 's': $finSeance=true; break;
|
|
case 'v': $checkIsin=true; break;
|
|
case 'e': $easyBourse=true; break;
|
|
case 'c': $isin=trim(substr($argv[$i],3,12));
|
|
if (strlen($isin)<>12) die('Code ISIN "'.$isin.'" incorrect !'.EOL); break;
|
|
case 'a': $allIsin=true; break;
|
|
case 'p': $getIPO=true; break;
|
|
case 'h': $isinHisto=trim(substr($argv[$i],3,12));
|
|
if (strlen($isinHisto)==0) $isinHisto=true;
|
|
elseif (strlen($isinHisto)<>12) die('Code ISIN "'.$isinHisto.'" incorrect !'.EOL); break;
|
|
case '-': die($strInfoProg); break;
|
|
default: die('Option '. $argv[$i] . " inconnue !\n"); break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($easyBourse) {
|
|
getEasyBourse();
|
|
die();
|
|
}
|
|
if($isin || $allIsin || $marcheRad || $marcheNew) {
|
|
$tabIsins=array();
|
|
//if ($allIsin) {
|
|
|
|
if ($marcheRad) {
|
|
/** Radiations de la Bourse **/
|
|
$url='http://www.abcbourse.com/marches/radiations.aspx';
|
|
$cookie=$referer='';
|
|
$page=getUrl($url, $cookie, ''/*$postData*/, $referer);
|
|
$referer=$url;
|
|
// randsleep(7,21);
|
|
/*
|
|
if (!preg_match('/ id="__VIEWSTATE" value="(.*)">/Uis', $page['body'], $matches))
|
|
die('Page inatendue !'.EOL);
|
|
$VIEWSTATE=$matches[1];
|
|
$tabRetr=array();
|
|
|
|
$postData=array('__EVENTTARGET'=>'',
|
|
'__EVENTARGUMENT'=>'',
|
|
'__LASTFOCUS'=>'',
|
|
'__VIEWSTATE'=>$VIEWSTATE);
|
|
|
|
$page=getUrl($url, $cookie, $postData, $referer);
|
|
*/
|
|
$tabRetr=array();
|
|
if (preg_match_all('/<tr(?:|.bgcolor="#EBEBEB")>(?:.*)<td align=".*" height=".*">(.*)<\/td>(?:.*)<td align=".*">(.*)<\/td>(?:.*)<td align=".*">(.*)<\/td>(?:.*)<\/tr>/Uis', $page['body'], $matches)) {
|
|
foreach ($matches[1] as $i=>$date) {
|
|
if ($i==0) continue;
|
|
elseif ($i==1) $annee=substr($date,-4);
|
|
|
|
$nom=htm2txt(utf8_decode($matches[3][$i]));
|
|
$tabRetr[]=array( 'date'=>$date,
|
|
// 'isin'=>$isin,
|
|
// 'siren'=>$siren,
|
|
'nom'=>$nom,
|
|
'marche'=>htm2txt($matches[2][$i]),
|
|
'url'=>"http://www.google.fr/#hl=fr&source=hp&q=".urlencode('"'.$nom.'"')."+rcs+isin+FR&btnG=Recherche+Google&meta=&aq=f"
|
|
);
|
|
}
|
|
// print_r($tabRetr);
|
|
$strObjet="Radiations de la bourse $annee";
|
|
$strMailInfo.="Les entreprises suivantes seront/sont radiés sur les marchés au cours de l'année $annee.".EOL.
|
|
"Penser à mettre à jour les informations sur la base...".EOL.EOL;
|
|
$strMailInfo.="Date\tRaison Sociale\tMarché\tLien".EOL;
|
|
foreach ($tabRetr as $tabMarche)
|
|
$strMailInfo.= $tabMarche['date']."\t".
|
|
$tabMarche['nom']."\t".
|
|
$tabMarche['marche']."\t".
|
|
$tabMarche['url'].EOL;
|
|
$strMailInfo.= EOL.EOL.EOL."--------------------------------------------------------------------".EOL.
|
|
"La liste peut être consultée à l'adresse suivante :".EOL.$url;
|
|
} else {
|
|
$strObjet="Radiations de la bourse $annee (ERREUR)";
|
|
$strMailInfo.="Erreur lors de la lecture des radiations sur les marchés au cours de l'année $annee depuis la liste suivante :".EOL.$url;
|
|
}
|
|
sendMail('webmaster@scores-decisions.com', 'support@scores-decisions.com', $strObjet, $strMailInfo);
|
|
}
|
|
|
|
|
|
if ($marcheNew) {
|
|
|
|
/*
|
|
POST http://www.abcbourse.com/marches/intros.aspx?ctl00%24BodyABC%24ddYear=2005 Indicateurs chargement[LOAD_DOCUMENT_URI LOAD_INITIAL_DOCUMENT_URI ] Taille contenu[7217] Type Mime[text/html]
|
|
En-têtes requête:
|
|
Referer[http://www.abcbourse.com/marches/intros.aspx?ctl00%24BodyABC%24ddYear=2005]
|
|
Cookie[__utma=107798994.177609469.1286568099.1286786199.1286878712.4; __utmc=107798994; __utmz=107798994.1286568099.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=107798994.7.10.1286878712]*/
|
|
|
|
$eventValidation='';
|
|
$viewState='';
|
|
$postData=array(
|
|
'__EVENTTARGET'=>'ctl00%24BodyABC%24ddYear',
|
|
'__EVENTARGUMENT'=>'',
|
|
'__LASTFOCUS'=>'',
|
|
'__VIEWSTATE'=>$viewState,
|
|
'__EVENTVALIDATION'=>$eventValidation,
|
|
'ctl00%24txtAutoComplete'=>'Chercher+une+valeur',
|
|
'ctl00%24BodyABC%24ddYear'=>$annee);
|
|
|
|
|
|
|
|
/** Introductions en Bourse **/
|
|
$url='http://www.abcbourse.com/marches/intros.aspx';
|
|
$cookie=$referer='';
|
|
$page=getUrl($url, $cookie, ''/*$postData*/, $referer);
|
|
// randsleep(7,21);
|
|
$referer=$url;
|
|
|
|
$tabIntro=array();
|
|
if (preg_match_all('/<tr(?:|.bgcolor="#EBEBEB")>(?:.*)'.
|
|
'<td align=".*" height=".*">(.*)<\/td>(?:.*)'.
|
|
'<td align=".*"> <a href="..\/graphes\/display\.aspx\?s=(.*)<\/a><\/td>(?:.*)'.
|
|
'<td align=".*">(.*)<\/td>(?:.*)'.
|
|
'<td align=".*">(.*)<\/td>(?:.*)'.
|
|
'<td align=".*">(.*)<\/td>(?:.*)<\/tr>/Uis', $page['body'], $matches)) {
|
|
foreach ($matches[1] as $i=>$date) {
|
|
if ($i==0) continue;
|
|
elseif ($i==1) $annee=substr($date,-4);
|
|
$tmp=explode('"', $matches[2][$i]);
|
|
$codep=str_replace(' ','',$tmp[0]);
|
|
$code=trim(preg_replace('/p$/','',$codep));
|
|
$nom=trim(str_replace('>',' ',$tmp[1]));
|
|
$url2="http://www.abcbourse.com/graphes/display.aspx?s=".$codep;
|
|
$page=getUrl($url2, $cookie, ''/*$postData*/, $referer);
|
|
randsleep(7,21);
|
|
if (preg_match('/<font color="gray">ticker\:(.*) ISIN\:(.*)<\/font>/Uis', $page['body'], $matches2)) {
|
|
$codeLu=trim($matches2[1]);
|
|
$isin=trim($matches2[2]);
|
|
} else
|
|
$codeLu=$isin='';
|
|
$siren=@$iBourse->getCodeSiren($isin)*1;
|
|
|
|
if ($isin<>'' && substr($isin,0,2)=='FR') $pays='FR';
|
|
elseif ($isin<>'' && substr($isin,0,2)<>'FR') $pays=substr($isin,0,2);
|
|
else $pays='';
|
|
|
|
if ($isin<>'') $tabIsins[]=$isin;
|
|
|
|
$tabIntro[]=array( 'date'=>$date,
|
|
'code'=>$code,
|
|
'isin'=>$isin,
|
|
'siren'=>$siren,
|
|
'nom'=>$nom,
|
|
'marche'=>htm2txt($matches[3][$i]),
|
|
'titres'=>htm2txt(utf8_decode($matches[4][$i])),
|
|
'prix'=>htm2txt($matches[5][$i]),//".urlencode('"'.$nom.'"')."
|
|
'url'=>"http://www.google.fr/#hl=fr&source=hp&q=$code+rcs+isin&btnG=Recherche+Google&meta=&aq=f"
|
|
);
|
|
}
|
|
// print_r($tabIntro);
|
|
|
|
$strObjet="Introductions en bourse $annee";
|
|
$strMailInfo.="Les entreprises suivantes seront/sont introduites sur les marchés au cours de l'année $annee.".EOL.
|
|
"Penser à mettre à jour les informations sur la base, principalement pour les siren à 0...".EOL.EOL;
|
|
$strMailInfo.="Date\tCode\tISIN\tSIREN\tRaison Sociale\tMarché\tLien".EOL;
|
|
foreach ($tabIntro as $tabMarche)
|
|
$strMailInfo.= $tabMarche['date']."\t".
|
|
$tabMarche['code']."\t".
|
|
$tabMarche['isin']."\t".
|
|
$tabMarche['siren']."\t".
|
|
$tabMarche['nom']."\t".
|
|
$tabMarche['marche']."\t".
|
|
$tabMarche['url'].EOL;
|
|
$strMailInfo.= EOL.EOL.EOL."--------------------------------------------------------------------".EOL.
|
|
"La liste complète des introductions peut être consultée à l'adresse suivante :".EOL.$url;
|
|
} else {
|
|
$strObjet="Introductions en bourse $annee (ERREUR)";
|
|
$strMailInfo.="Erreur lors de la lecture des introductions sur les marchés au cours de l'année $annee depuis la liste suivante :".EOL.$url;
|
|
}
|
|
sendMail('webmaster@scores-decisions.com', 'support@scores-decisions.com', $strObjet, $strMailInfo);
|
|
//die();
|
|
}
|
|
|
|
//print_r(getInfosIsin('FR0010050773'));
|
|
//die();
|
|
|
|
if ($allIsin) {
|
|
echo date('Y/m/d - H:i:s') ." - DEBUT du la mise à jour des informations ISIN sur les entreprises...".EOL;
|
|
echo date('Y/m/d - H:i:s') .' - La durée maximum entre chaque requête est de '. $tempsMaxEntreRequetes .' secondes.'. EOL;
|
|
/** @todo
|
|
* 1. Ne pas mettre à jour tous les ISIN mis à jour dernièrement
|
|
* 2. Récupérer les isin FR non existant dans cette table
|
|
**/
|
|
echo date('Y/m/d - H:i:s') .' - Recherche des codes Isin récents ...... '.count($tabIsins).' créations dans l\'année'.EOL;
|
|
|
|
$tabTmp=$iDb2->select('bourse_isin', 'code_isin', "dateRadiation IS NULL AND DATE_ADD(dateUpdate, INTERVAL 31 DAY) < NOW()", false, MYSQL_ASSOC);
|
|
foreach ($tabTmp as $i=>$isin)
|
|
$tabIsins[]=$isin['code_isin'];
|
|
echo date('Y/m/d - H:i:s') .' - Recherche des codes Isin S&D .......... '.count($tabTmp).' valeurs.'.EOL;
|
|
|
|
$tabTmp=$iDb2->select('societe_identification', 'isin AS code_isin', "1", false, MYSQL_ASSOC);
|
|
foreach ($tabTmp as $i=>$isin)
|
|
$tabIsins[]=$isin['code_isin'];
|
|
echo date('Y/m/d - H:i:s') .' - Recherche des codes Isin Cofisem ...... '.count($tabTmp).' valeurs.'.EOL;
|
|
|
|
$tabTmp=$iDb->select('infos_entrep', 'isin AS code_isin', "isin NOT IN ('', 'DELISTE')", false, MYSQL_ASSOC);
|
|
foreach ($tabTmp as $i=>$isin)
|
|
$tabIsins[]=$isin['code_isin'];
|
|
echo date('Y/m/d - H:i:s') .' - Recherche des codes Isin Entrep S&D ... '.count($tabTmp).' valeurs.'.EOL;
|
|
|
|
/* $tabTmp=$iDb2->select('bourse_listes', 'DISTINCT isin AS code_isin', "isin LIKE 'FR%'", false, MYSQL_ASSOC);
|
|
foreach ($tabTmp as $i=>$isin)
|
|
$tabIsins[]=$isin['code_isin'];
|
|
echo date('Y/m/d - H:i:s') .' - Recherche des mises à jour sur le référentiel Listes Isin :'.count($tabTmp).' valeurs.'.EOL;
|
|
*/
|
|
} else $tabIsins[0]=$isin;
|
|
|
|
$tabIsins=array_unique($tabIsins);
|
|
shuffle($tabIsins);
|
|
$nbIsin=count($tabIsins);
|
|
if ($nbIsin>1) echo date ('Y/m/d - H:i:s') ." - Il y a $nbIsin codes ISIN à mettre à jour...". EOL;
|
|
elseif ($nbIsin==0) echo date ('Y/m/d - H:i:s') ." - Il n'y a aucun code ISIN à mettre à jour !". EOL;
|
|
foreach ($tabIsins as $i=>$isin)
|
|
{
|
|
echo date ('Y/m/d - H:i:s') ." - Traitement du code ISIN $isin...". EOL;
|
|
// On regarde ce qu'il y a en base !
|
|
$tabTmp=$iDb2->select('bourse_isin', 'siren, raisonSociale, effectif, code_sicovam, dateIntroduction, nombreTitres, web, mail, dateInsert, dateUpdate', "code_isin='$isin'");
|
|
$tabIsin=$tabTmp[0];
|
|
// On récupère les infos disponibles sur les sites spécialisés
|
|
$tabUpdate=@getInfosIsin($isin);
|
|
$raisonSociale=$tabUpdate['raisonSociale'];
|
|
|
|
/** Champs qu'on ne veux pas effacer si déjà remplis **/
|
|
if ($tabUpdate['dateIntroduction']=='') unset($tabUpdate['dateIntroduction']);
|
|
if ($tabUpdate['nombreTitres']=='') unset($tabUpdate['nombreTitres']);
|
|
if ($tabUpdate['web']=='') unset($tabUpdate['web']);
|
|
if ($tabUpdate['mail']=='') unset($tabUpdate['mail']);
|
|
if ($tabUpdate['tel1']=='') unset($tabUpdate['tel1']);
|
|
if ($tabUpdate['fax1']=='') unset($tabUpdate['fax1']);
|
|
if ($tabUpdate['tel2']=='') unset($tabUpdate['tel2']);
|
|
if ($tabUpdate['fax2']=='') unset($tabUpdate['fax2']);
|
|
if ($tabUpdate['effectif']=='') unset($tabUpdate['effectif']);
|
|
if ($tabUpdate['code_sicovam']=='') unset($tabUpdate['code_sicovam']);
|
|
|
|
if ($tabUpdate['code_boursorama']=='') {
|
|
/** Le titre n'est pas référencé sur Boursorama.com
|
|
**/
|
|
echo date ('Y/m/d - H:i:s') ." - Le code ISIN $isin n'est plus référencé ($raisonSociale)". EOL;
|
|
$tabUpdate['deliste']=1;
|
|
unset($tabUpdate['code_boursorama']);
|
|
unset($tabUpdate['nombreTitres']);
|
|
unset($tabUpdate['secteur']);
|
|
unset($tabUpdate['marche']);
|
|
unset($tabUpdate['placeCotation']);
|
|
unset($tabUpdate['eligibleSRD']);
|
|
unset($tabUpdate['activiteDet']);
|
|
unset($tabUpdate['effectif']);
|
|
unset($tabUpdate['dateDerAG']);
|
|
unset($tabUpdate['adresse']);
|
|
unset($tabUpdate['tel1']);
|
|
unset($tabUpdate['fax1']);
|
|
unset($tabUpdate['web']);
|
|
unset($tabUpdate['dirigeants']);
|
|
unset($tabUpdate['actionnaires']);
|
|
unset($tabUpdate['chiffresTrim']);
|
|
} else {
|
|
$tabUpdate['deliste']=0;
|
|
$tabUpdate['dirigeants']='';//serialize($tabUpdate['dirigeants']);
|
|
$tabUpdate['actionnaires']='';//serialize($tabUpdate['actionnaires']);
|
|
$tabUpdate['chiffresTrim']='';//serialize($tabUpdate['chiffresTrim']);
|
|
}
|
|
if ($tabUpdate['siren']*1==0)
|
|
$tabUpdate['siren']=@$iBourse->getCodeSiren($isin);
|
|
print_r($tabUpdate);
|
|
$ret=$iDb2->insert('bourse_isin', array_merge(array('dateInsert'=>date('YmdHis')),$tabUpdate));
|
|
if ($ret==0) {
|
|
// $iDb2->insert('bourse_isin', $tabUpdate, true);
|
|
$ret=$iDb2->update('bourse_isin', $tabUpdate, "code_isin='$isin'", true);
|
|
echo date ('Y/m/d - H:i:s') ." - Mise à jour des informations pour $isin $raisonSociale". EOL;
|
|
//$ret=1;
|
|
} else
|
|
echo date ('Y/m/d - H:i:s') ." - Création des informations pour $isin $raisonSociale". EOL;
|
|
|
|
if (!$allIsin) die();
|
|
}
|
|
echo date('Y/m/d - H:i:s') .' - FIN du script.'. EOL;
|
|
die();
|
|
|
|
// http://www.europafinance.com/
|
|
|
|
// Rapports annuels
|
|
// Récupérer la liste des sites des rapports sur le site de l'amf
|
|
}
|
|
|
|
$strDates=$strLast=$strMailInfo='';
|
|
|
|
if (!$checkIsin && !$isinHisto) {
|
|
if ($dernierCour || $finSeance) $strLast=' dernières';
|
|
else {
|
|
$dateCour=$dateDeb;
|
|
$strLast='';
|
|
if ($dateDebut==false || $dateFin==false)
|
|
die($strInfoProg);
|
|
else
|
|
$strDates=" du $dateDebut au $dateFin";
|
|
}
|
|
$strMailInfo.=date('Y/m/d - H:i:s') ." - Récupération des cotation des$strLast cotations$strDates...".EOL;
|
|
echo date('Y/m/d - H:i:s') ." - DEBUT du la récupération des$strLast cotations$strDates...".EOL;
|
|
echo date('Y/m/d - H:i:s') .' - La durée maximum entre chaque requête est de '. $tempsMaxEntreRequetes .' secondes.'. EOL;
|
|
$referer=$cookie=$postData='';
|
|
|
|
while ($dateCour<=$dateF || $dernierCour || $finSeance) {
|
|
|
|
if ( ($dernierCour && (date('H')<9||date('H')>18)) || $finSeance) {
|
|
if (date('H')<9)
|
|
$tsTmp=mktime(0, 0, 0, date('m'), date('d')-1, date('Y'));
|
|
else
|
|
$tsTmp=mktime(0, 0, 0, date('m'), date('d'), date('Y'));
|
|
$finSeance=true;
|
|
$checkIsin=true;
|
|
$deb_j=$fin_j=date('d', $tsTmp)*1;
|
|
$deb_m=$fin_m=date('m', $tsTmp)*1;
|
|
$deb_Y=$fin_Y=date('Y', $tsTmp);
|
|
echo date('Y/m/d - H:i:s') ." - Cotation terminée : On charge les cotations de fin de séance du $deb_j/$deb_m/$deb_Y !". EOL;
|
|
$url=URL_BOURSE_HISTO;
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie, ''/*$postData*/, $referer);
|
|
if (preg_match('/ id="__VIEWSTATE" value="(.*)" /Ui', $page['body'],$matches))
|
|
$viewstate=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant de session "__VIEWSTATE"');
|
|
|
|
if (preg_match('/__EVENTVALIDATION" value="(.*)"/i', $page['body'],$matches))
|
|
$eventValidation=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant "__EVENTVALIDATION"');
|
|
|
|
$cookie=@$page['header']['Set-Cookie'];
|
|
|
|
$referer=$url;
|
|
$postData=array(//'ctl00_autocompleteUser1_ToolkitScriptManager1_HiddenField'=>'',
|
|
'ctl00_BodyABC_ToolkitScriptManager1_HiddenField'=>'',
|
|
'__EVENTTARGET'=>'',
|
|
'__EVENTARGUMENT'=>'',
|
|
'__VIEWSTATE'=>urlencode($viewstate),
|
|
'ctl00%24txtAutoComplete'=>'',
|
|
'ctl00%24BodyABC%24strDateDeb'=>$deb_j.'%2F'.$deb_m.'%2F'.$deb_Y,
|
|
'ctl00%24BodyABC%24strDateFin'=>$fin_j.'%2F'.$fin_m.'%2F'.$fin_Y,
|
|
'ctl00%24BodyABC%24txtOneSico'=>'',
|
|
'ctl00%24BodyABC%24complet'=>'on',
|
|
'ctl00%24BodyABC%24cbYes'=>'on',
|
|
'ctl00%24BodyABC%24dlFormat'=>'m',
|
|
'ctl00%24BodyABC%24listFormat'=>'isin',
|
|
'ctl00%24BodyABC%24ImageButton1.x'=>rand(1,89),
|
|
'ctl00%24BodyABC%24ImageButton1.y'=>rand(1,22),
|
|
'__EVENTVALIDATION'=>urlencode($eventValidation),
|
|
);
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie, $postData, $referer);
|
|
}
|
|
elseif ($dernierCour) {
|
|
$url=URL_BOURSE_COURS;
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie, ''/*$postData*/, $referer);
|
|
if (preg_match('/ id="__VIEWSTATE" value="(.*)" /Ui', $page['body'],$matches))
|
|
$viewstate=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant de session "__VIEWSTATE"');
|
|
if (preg_match('/__EVENTVALIDATION" value="(.*)"/Ui', $page['body'],$matches))
|
|
$eventValidation=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant "__EVENTVALIDATION"');
|
|
$referer=$url;
|
|
|
|
$postData=array(//'ctl00_autocompleteUser1_ToolkitScriptManager1_HiddenField'=>'',
|
|
// 'ctl00_BodyABC_ToolkitScriptManager1_HiddenField'=>'',
|
|
// '__EVENTTARGET'=>'',
|
|
// '__EVENTARGUMENT'=>'',
|
|
'__VIEWSTATE'=>urlencode($viewstate),
|
|
'ctl00%24txtAutoComplete'=>'',
|
|
'ctl00%24BodyABC%24f'=>'ms', // w:Format Waldata, ms:Format Metastock, ebp:Format EBP, b:Boursitel, fa:Finance Audience
|
|
'ctl00%24BodyABC%24m'=>'complet',
|
|
'ctl00%24BodyABC%24Button1'=>'T%C3%A9l%C3%A9charger',
|
|
//'ctl00%24BodyABC%24ImageButton1.x'=>rand(1,89),
|
|
//'ctl00%24BodyABC%24ImageButton1.y'=>rand(1,22),
|
|
'__EVENTVALIDATION'=>urlencode($eventValidation),
|
|
);
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie, $postData, $referer);
|
|
}
|
|
else {
|
|
$dateTmp=WDate::dateT('Ymd', 'd/m/Y',$dateCour);
|
|
$jourSem=date('w',mktime(0, 0, 0, WDate::dateT('Ymd','m', $dateCour), WDate::dateT('Ymd','d', $dateCour), WDate::dateT('Ymd','Y', $dateCour)));
|
|
if ($tabJour[$jourSem]=='Sam' || $tabJour[$jourSem]=='Dim') {
|
|
echo date('Y/m/d - H:i:s') .' - On ignore les cotations pour le '.$tabJour[$jourSem].' '.$dateTmp.' (Week-end).'. EOL;
|
|
$dateCour=getNextDate($dateCour, 1);
|
|
continue;
|
|
}
|
|
$tabTmp=explode('/', $dateTmp);
|
|
$deb_j=$fin_j=$tabTmp[0]*1;
|
|
$deb_m=$fin_m=$tabTmp[1]*1;
|
|
$deb_Y=$fin_Y=$tabTmp[2];
|
|
if (($deb_j==1 && $deb_m==1) ||
|
|
($deb_j==1 && $deb_m==5) ||
|
|
($deb_j==8 && $deb_m==5) ||
|
|
($deb_j==14 && $deb_m==7) ||
|
|
($deb_j==15 && $deb_m==8) ||
|
|
($deb_j==1 && $deb_m==11) ||
|
|
($deb_j==11 && $deb_m==11) ||
|
|
($deb_j==25 && $deb_m==12) ) {
|
|
echo date('Y/m/d - H:i:s') .' - On ignore les cotations pour le '.$tabJour[$jourSem].' '.$dateTmp.' (Férié).'. EOL;
|
|
$dateCour=getNextDate($dateCour, 1);
|
|
continue;
|
|
}
|
|
$strMailInfo.=date('Y/m/d - H:i:s') .' - Récupération des cotation pour le '.$tabJour[$jourSem].' '.$dateTmp.'...'. EOL;
|
|
echo date('Y/m/d - H:i:s') .' - Récupération des cotation pour le '.$tabJour[$jourSem].' '.$dateTmp.'...'. EOL;
|
|
$url=URL_BOURSE_HISTO;
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie, ''/*$postData*/, $referer);
|
|
//<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwNDI1NTE2ODZkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYlBRJjdGwwMCRJbWFnZUJ1dHRvbjEFEmN0bDAwJEJvZHlBQkMkc3JkcAUYY3RsMDAkQm9keUFCQyRldXJvbGlzdGFwBRhjdGwwMCRCb2R5QUJDJGV1cm9saXN0YnAFGGN0bDAwJEJvZHlBQkMkZXVyb2xpc3RjcAUZY3RsMDAkQm9keUFCQyRldXJvbGlzdHplcAUaY3RsMDAkQm9keUFCQyRldXJvbGlzdGh6ZXAFFGN0bDAwJEJvZHlBQkMkYWx0ZXJwBRRjdGwwMCRCb2R5QUJDJG5tc3BlcAUQY3RsMDAkQm9keUFCQyRtbAUUY3RsMDAkQm9keUFCQyR0cmFja3AFE2N0bDAwJEJvZHlBQkMkcG10cHAFEWN0bDAwJEJvZHlBQkMkYnNwBRVjdGwwMCRCb2R5QUJDJHhjYWM0MHAFFmN0bDAwJEJvZHlBQkMkeHNiZjEyMHAFFmN0bDAwJEJvZHlBQkMkeHNiZjI1MHAFFWN0bDAwJEJvZHlBQkMkeGl0Y2FjcAUXY3RsMDAkQm9keUFCQyR4Y2FjaXQyMHAFFmN0bDAwJEJvZHlBQkMkeGNhY24yMHAFFmN0bDAwJEJvZHlBQkMkeGNhY3M5MHAFF2N0bDAwJEJvZHlBQkMkeGNhY20xMDBwBRhjdGwwMCRCb2R5QUJDJHhjYWNtczE5MHAFEmN0bDAwJEJvZHlBQkMkb2JscAUWY3RsMDAkQm9keUFCQyR3YXJyYW50cwUSY3RsMDAkQm9keUFCQyRkZXZwBRFjdGwwMCRCb2R5QUJDJGRqdQUSY3RsMDAkQm9keUFCQyRuYXN1BRhjdGwwMCRCb2R5QUJDJGluZGljZXNGUnAFEmN0bDAwJEJvZHlBQkMkZmNwcAUVY3RsMDAkQm9keUFCQyRvbmVTaWNvBRZjdGwwMCRCb2R5QUJDJGV1cm9saXN0BRxjdGwwMCRCb2R5QUJDJGFjdGlvbnNpbmRpY2VzBRpjdGwwMCRCb2R5QUJDJGFjdGlvbnNpbmR1cwUVY3RsMDAkQm9keUFCQyRjb21wbGV0BRtjdGwwMCRCb2R5QUJDJGNvbXBsZXRub3dhcnIFE2N0bDAwJEJvZHlBQkMkY2JZZXMFGmN0bDAwJEJvZHlBQkMkSW1hZ2VCdXR0b24xqNG+hkiU5S8IW+PRQmOueOKcP2w=" />
|
|
//die($page['body']);
|
|
if (preg_match('/ id="__VIEWSTATE" value="(.*)" /Ui', $page['body'],$matches))
|
|
$viewstate=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant de session "__VIEWSTATE"');
|
|
if (preg_match('/__EVENTVALIDATION" value="(.*)"/i', $page['body'],$matches))
|
|
$eventValidation=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant "__EVENTVALIDATION"');
|
|
//$cookie=@$page['header']['Cookie'];
|
|
$cookie=@$page['header']['Set-Cookie'];
|
|
// echo date ('Y/m/d - H:i:s') ." - Cookies=$cookie".EOL;
|
|
// echo date ('Y/m/d - H:i:s') ." - Identifiant __VIEWSTATE=$viewstate".EOL;
|
|
// echo date ('Y/m/d - H:i:s') ." - Identifiant __EVENTVALIDATION=$eventValidation".EOL;
|
|
$referer=$url;
|
|
$postData=array(//'ctl00_autocompleteUser1_ToolkitScriptManager1_HiddenField'=>'',
|
|
'ctl00_BodyABC_ToolkitScriptManager1_HiddenField'=>'',
|
|
'__EVENTTARGET'=>'',
|
|
'__EVENTARGUMENT'=>'',
|
|
'__VIEWSTATE'=>urlencode($viewstate),
|
|
//'ctl00%24autocompleteUser1%24TextBox1'=>'',
|
|
'ctl00%24txtAutoComplete'=>'',
|
|
//'ctl00%24autocompleteUser1%24TextBox1_TextBoxWatermarkExtender_ClientState'=>'',
|
|
'ctl00%24BodyABC%24strDateDeb'=>$deb_j.'%2F'.$deb_m.'%2F'.$deb_Y,
|
|
'ctl00%24BodyABC%24strDateFin'=>$fin_j.'%2F'.$fin_m.'%2F'.$fin_Y,
|
|
'ctl00%24BodyABC%24txtOneSico'=>'',
|
|
'ctl00%24BodyABC%24complet'=>'on',
|
|
'ctl00%24BodyABC%24cbYes'=>'on',
|
|
'ctl00%24BodyABC%24dlFormat'=>'m',
|
|
'ctl00%24BodyABC%24listFormat'=>'isin',
|
|
'ctl00%24BodyABC%24ImageButton1.x'=>rand(1,89),
|
|
'ctl00%24BodyABC%24ImageButton1.y'=>rand(1,22),
|
|
'__EVENTVALIDATION'=>urlencode($eventValidation),
|
|
);
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie, $postData, $referer);
|
|
}
|
|
|
|
//print_r($page);die();
|
|
|
|
if (!isset($page['header']['Content-Disposition'])) {
|
|
if (preg_match('/^HTTP\/1\.1 200 OK(?:.*)Content-Disposition\:(?:.*)\r\n\r\n(.*)$/Uis', $page['body'], $matches)) {
|
|
$page['body']=$matches[1];
|
|
} else {
|
|
if($dernierCour || $finSeance) {
|
|
$message=date ('Y/m/d - H:i:s') .' - ERREUR : Pas de fichier !';
|
|
echo $message;
|
|
$strMailInfo.=$message;
|
|
sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', 'Téléchargement des cours de bourse', $strMailInfo.EOL.print_r($page,1));
|
|
die();
|
|
} else {
|
|
echo date('Y/m/d - H:i:s') .' - Pas de cotations pour le '.$dateTmp.' !'. EOL;
|
|
$dateCour=getNextDate($dateCour, 1);
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
$csv=$page['body'];
|
|
$tabLignes=explode ("\n",$csv);
|
|
$nbLignes=count($tabLignes);
|
|
if ($nbLignes<30) die(date ('Y/m/d - H:i:s') .' - ERREUR : Trop peu de lignes trouvées dans le flux : '.$nbLignes.' ligne(s)'.EOL);
|
|
$fp=@fopen(FILENAME_BOURSE_HISTO, 'a');
|
|
$ligne=explode(',', $tabLignes[0]);
|
|
if ($ligne[0]<>'<ticker>') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°1 ; balise <ticker> attendue'.EOL);
|
|
if ($ligne[1]<>'<date>') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°2 ; balise <date> attendue'.EOL);
|
|
if ($ligne[2]<>'<open>') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°3 ; balise <open> attendue'.EOL);
|
|
if ($ligne[3]<>'<high>') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°4 ; balise <high> attendue'.EOL);
|
|
if ($ligne[4]<>'<low>') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°5 ; balise <low> attendue'.EOL);
|
|
if ($ligne[5]<>'<close>') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°6 ; balise <close> attendue'.EOL);
|
|
if (trim($ligne[6])<>'<volume>') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°7 ; balise <volume> attendue'.EOL);
|
|
@fwrite($fp, $tabLignes[0]);
|
|
$ntraite=$traite=$error=0;
|
|
if ($finSeance || $dateCour)
|
|
$heure=1735;
|
|
else
|
|
$heure=date('Hi', mktime(date('H'),date('i')-15, date('s'), date('m'), date('d'), date('Y')));
|
|
|
|
if (!$finSeance && !$dateCour && $heure>=1735)
|
|
die(date('Y/m/d - H:i:s') ." - Arrêt de la récupération des valeurs courantes de la journée car il est $heure".EOL);
|
|
|
|
for ($i=1; $i<$nbLignes;$i++) {
|
|
$ligne=explode(',', $tabLignes[$i]);
|
|
if (trim($ligne[0])=='' && $i==$nbLignes-1) break;
|
|
$isin=substr($ligne[0],0,12);
|
|
$autre=trim(substr($ligne[0],12,strlen($ligne[0])-12));
|
|
@fwrite($fp, $tabLignes[$i]);
|
|
$ret=$iDb2->select('bourse_cours', 'count(*)', 'isin=\''. $isin.'\' AND '.
|
|
'autre=\''. $autre.'\' AND '.
|
|
'date=\''. $ligne[1].'\' AND '.
|
|
'open='. $ligne[2].' AND '.
|
|
'high='. $ligne[3].' AND '.
|
|
'low='. $ligne[4].' AND '.
|
|
'close='. $ligne[5].' AND '.
|
|
'volume='. $ligne[6]);
|
|
$deja=$ret[0][0];
|
|
if (!$deja) {
|
|
$traite++;
|
|
$tabInsert=array( 'isin'=>$isin,
|
|
'autre'=>$autre,
|
|
'date'=>$ligne[1],
|
|
'open'=>$ligne[2],
|
|
'high'=>$ligne[3],
|
|
'low'=>$ligne[4],
|
|
'close'=>$ligne[5],
|
|
'volume'=>trim($ligne[6]),
|
|
'heure'=>$heure,
|
|
);
|
|
if (!$iDb2->insert('bourse_cours', $tabInsert))
|
|
if (mysql_errno()<>1062)
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : MySql n°'. mysql_errno() .' : '. mysql_error() . EOL);
|
|
else $error++;
|
|
}
|
|
else $ntraite++;
|
|
}
|
|
@fclose($fp);
|
|
|
|
echo date('Y/m/d - H:i:s') .' - '. ($ntraite+$error) .' cotations déjà en base dont '.$error.' erreur(s) !'.EOL;
|
|
$strMailInfo.=date('Y/m/d - H:i:s') .' - '. ($ntraite+$error) .' cotations déjà en base dont '.$error.' erreur(s) !'.EOL;
|
|
echo date('Y/m/d - H:i:s') .' - '. $traite.' / '. ($nbLignes-2) .' cours téléchargés.'. EOL;
|
|
$strMailInfo.=date('Y/m/d - H:i:s') .' - '. $traite.' / '. ($nbLignes-2) .' cours téléchargés.'. EOL;
|
|
if($dernierCour || $finSeance) {
|
|
if ($finSeance)
|
|
sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', 'Téléchargement des cours de bourse', $strMailInfo);
|
|
break;
|
|
}
|
|
else $dateCour=getNextDate($dateCour, 1);
|
|
}
|
|
}
|
|
|
|
if ($checkIsin) {
|
|
/** @todo NE télécharger que les changements, çàd : entrée dans une liste ou sortie d'une liste !!!
|
|
**/
|
|
echo date ('Y/m/d - H:i:s') .' - Vérification des Listes ISIN (Cac, Eurolist, etc...)' . EOL;
|
|
$tabListes=array( 'srdp'=> 'SRD Français et Étrangers', // Service de Règlement Différé
|
|
'eurolistAp'=> 'Eurolist, Compartiment A',
|
|
'eurolistBp'=> 'Eurolist, Compartiment B',
|
|
'eurolistCp'=> 'Eurolist, Compartiment C',
|
|
'eurolistzep'=> 'Eurolist, Zone euro',
|
|
'eurolisthzep'=>'Eurolist, Hors zone euro',
|
|
'alterp'=> 'Alternext',
|
|
'nmspep'=> 'Compartiment Spécial',
|
|
'mlp'=> 'Marché Libre Français',
|
|
'mlep'=> 'Marché Libre Étrangers',
|
|
'trackp'=> 'Trackers',
|
|
'pmtpp'=> 'Titres participatifs',
|
|
'bsp'=> 'Bons de Souscription',
|
|
// Composition des indices
|
|
'xcac40p'=> 'Cac40',
|
|
'xsbf120p'=> 'Sbf120',
|
|
'xsbf250p'=> 'Sbf250',
|
|
'xitcacp'=> 'IT cac',
|
|
'xcacit20p'=> 'Cac It 20',
|
|
'xcacn20p'=> 'Cac Next 20',
|
|
'xcacs90p'=> 'Cac Small 90',
|
|
'xcacm100p'=> 'Cac Mid 100',
|
|
'xcacms190p'=> 'Cac Mid & Small 190',
|
|
//
|
|
'oblp'=> 'Obligations',
|
|
'warrants'=> 'Warrants',
|
|
'devp'=> 'Devises',
|
|
// Marchés US
|
|
'dju'=> 'Dow Jones',
|
|
'nasu'=> 'Nasdaq 100',
|
|
// Indices
|
|
'indicesFRp'=> 'Indices',
|
|
);
|
|
foreach ($tabListes as $lstCode=>$lstNom) {
|
|
$url=URL_BOURSE_LISTE;
|
|
$cookie='';
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie);
|
|
|
|
if (preg_match('/ id="__VIEWSTATE" value="(.*)" /Ui', $page['body'],$matches))
|
|
$viewstate=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant de session "__VIEWSTATE"');
|
|
|
|
if (preg_match('/__EVENTVALIDATION" value="(.*)"/i', $page['body'],$matches))
|
|
$eventValidation=$matches[1];
|
|
else die(date ('Y/m/d - H:i:s') .' - ERREUR : Impossible de récupérer l\'identifiant "__EVENTVALIDATION"');
|
|
//$cookie=@$page['header']['Cookie'];
|
|
$cookie=@$page['header']['Set-Cookie'];
|
|
/*
|
|
Données POST:
|
|
__VIEWSTATE[%2FwEPDwUKMjAyMjg3OTM4OWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFiQFFWN0bDAwJEJvZHlBQkMkeGNhYzQwcAUWY3RsMDAkQm9keUFCQyR4c2JmMTIwcAUVY3RsMDAkQm9keUFCQyR4Y2FjYXRwBRZjdGwwMCRCb2R5QUJDJHhjYWNuMjBwBRhjdGwwMCRCb2R5QUJDJHhjYWNzbWFsbHAFFWN0bDAwJEJvZHlBQkMkeGNhYzYwcAUWY3RsMDAkQm9keUFCQyR4Y2FjbDYwcAUVY3RsMDAkQm9keUFCQyR4Y2FjbXNwBRVjdGwwMCRCb2R5QUJDJHhiZWwyMGcFFWN0bDAwJEJvZHlBQkMkeGFleDI1bgURY3RsMDAkQm9keUFCQyRkanUFEmN0bDAwJEJvZHlBQkMkbmFzdQUUY3RsMDAkQm9keUFCQyRzcDUwMHUFEmN0bDAwJEJvZHlBQkMkdXNhdQUSY3RsMDAkQm9keUFCQyRiZWxnBRNjdGwwMCRCb2R5QUJDJGhvbGxuBRVjdGwwMCRCb2R5QUJDJGxpc2JvYWwFEmN0bDAwJEJvZHlBQkMkZGV2cAUUY3RsMDAkQm9keUFCQyRhbHRlcnAFEWN0bDAwJEJvZHlBQkMkYnNwBRhjdGwwMCRCb2R5QUJDJGV1cm9saXN0QXAFGGN0bDAwJEJvZHlBQkMkZXVyb2xpc3RCcAUYY3RsMDAkQm9keUFCQyRldXJvbGlzdENwBRljdGwwMCRCb2R5QUJDJGV1cm9saXN0emVwBRpjdGwwMCRCb2R5QUJDJGV1cm9saXN0aHplcAUYY3RsMDAkQm9keUFCQyRpbmRpY2VzbWtwBRljdGwwMCRCb2R5QUJDJGluZGljZXNzZWNwBRFjdGwwMCRCb2R5QUJDJG1scAUSY3RsMDAkQm9keUFCQyRtbGVwBRNjdGwwMCRCb2R5QUJDJG9ibDJwBRJjdGwwMCRCb2R5QUJDJGZjcHAFEmN0bDAwJEJvZHlBQkMkc3JkcAUUY3RsMDAkQm9keUFCQyRzcmRsb3AFFGN0bDAwJEJvZHlBQkMkdHJhY2twBRZjdGwwMCRCb2R5QUJDJHdhcnJhbnRzBRVjdGwwMCRCb2R5QUJDJGNiUGxhY2UF0%2FcY%2Fzu2RgCVaIrnEWXd5FFhjA%3D%3D]
|
|
__EVENTVALIDATION[%2FwEWKALfwM6sAwKPgp47AuX3t%2B0NApeY0uUNArGJ%2BZcLAqDEhNQNAvXt%2B%2BwMApma3OYLAs3qjZACAr%2Bb8NUFAuSyzpoDAvrGrrwMAvPGhsMEAp6bvJgIAo7%2F6cIPAoiY%2F34ClfG83AIC6%2B3nrgwC%2FPC9%2BgcCnOOzhwECn5vYgwgCl4yI%2FQYCz%2B3rxA8C6ey36QwCmLHeqQ4Cs5r8vggC58Gmvw4C2qfbwg4ChNbnyQwC2eCLwwIC3LqTugIC8brTugICi4u3xg0C48j0ogICzsPYqw4CzM7D7gECpqOX%2BQgC9Nmq0gsC34%2BxowYCvKXGggjBkW8Kp%2FwqR1huUw4xnZE1IpqfBw%3D%3D]
|
|
|
|
*/
|
|
$referer=$url;
|
|
$postData=array(//'ctl00_autocompleteUser1_ToolkitScriptManager1_HiddenField'=>'',
|
|
//'__EVENTTARGET'=>'',
|
|
//'__EVENTARGUMENT'=>'',
|
|
'__VIEWSTATE'=>urlencode($viewstate),
|
|
'__EVENTVALIDATION'=>urlencode($eventValidation),
|
|
'ctl00%24txtAutoComplete'=>'',
|
|
//'ctl00%24autocompleteUser1%24TextBox1_TextBoxWatermarkExtender_ClientState'=>'',
|
|
'ctl00%24BodyABC%24'.$lstCode=>'on',
|
|
'ctl00%24BodyABC%24Button1'=>'T%C3%A9l%C3%A9charger',
|
|
//'ctl00%24BodyABC%24ImageButton1.y'=>rand(1,22),
|
|
);
|
|
randsleep($tempsMinEntreRequetes,$tempsMaxEntreRequetes);
|
|
$page=getUrl($url, $cookie, $postData, $referer);
|
|
if (!isset($page['header']['Content-Disposition'])) {
|
|
if (preg_match('/^HTTP\/1\.1 200 OK(?:.*)Content-Disposition\:(?:.*)\r\n\r\n(.*)$/Uis', $page['body'], $matches))
|
|
$page['body']=$matches[1];
|
|
else {
|
|
//print_r($page);
|
|
$message=date ('Y/m/d - H:i:s') ." - ERREUR : Pas de fichier pour la liste \"$lstNom\" (code=$lstCode) !".EOL;
|
|
echo $message;
|
|
$strMailInfo.=$message;
|
|
}
|
|
}
|
|
echo(date ('Y/m/d - H:i:s') ." - Téléchargement de la liste \"$lstNom\" (code=$lstCode)...".EOL);
|
|
$csv=$page['body'];
|
|
$tabLignes=explode ("\n",$csv);
|
|
$nbLignes=count($tabLignes);
|
|
if ($nbLignes<3) {
|
|
$message=date ('Y/m/d - H:i:s') ." - Attention : Pas assez de lignes trouvées pour la liste \"$lstNom\" (code=$lstCode) : $nbLignes ligne(s)".EOL;
|
|
echo $message;
|
|
$strMailInfo.=$message;
|
|
}
|
|
$fp=@fopen('/tmp/fluxbourselistes.csv', 'a');
|
|
$ligne=explode(';', $tabLignes[0]);
|
|
if ($ligne[0]<>'ISIN') {
|
|
$message=date ('Y/m/d - H:i:s') ." - ERREUR : Liste \"$lstNom\" (code=$lstCode), première ligne, champ n°1 ; balise \"ISIN\" attendue".EOL;
|
|
echo $message;
|
|
$strMailInfo.=$message;
|
|
break;
|
|
}
|
|
if ($ligne[1]<>'nom') {
|
|
$message=date ('Y/m/d - H:i:s') ." - ERREUR : Liste \"$lstNom\" (code=$lstCode), première ligne, champ n°2 ; balise \"nom\" attendue".EOL;
|
|
echo $message;
|
|
$strMailInfo.=$message;
|
|
break;
|
|
}
|
|
// if ($ligne[2]<>'sicovam') die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, champ n°3 ; balise "sicovam" attendue'.EOL);
|
|
if (trim($ligne[2])<>'ticker') {
|
|
$message=date ('Y/m/d - H:i:s') ." - ERREUR : Liste \"$lstNom\" (code=$lstCode), première ligne, champ n°3 ; balise \"ticker\" attendue".EOL;
|
|
echo $message;
|
|
$strMailInfo.=$message;
|
|
break;
|
|
}
|
|
@fwrite($fp, $tabLignes[0]);
|
|
$ntraite=$traite=$error=0;
|
|
|
|
for ($i=1; $i<$nbLignes;$i++) {
|
|
$ligne=explode(';', $tabLignes[$i]);
|
|
if (trim($ligne[0])=='' && $i==$nbLignes-1) break;
|
|
$isin=substr($ligne[0],0,12);
|
|
$autre=trim(substr($ligne[0],12,strlen($ligne[0])-12));
|
|
@fwrite($fp, $tabLignes[$i]);
|
|
/* $ret=mysql_select('bourse_cours', 'count(*)', 'isin=\''. $isin.'\' AND '.
|
|
'autre=\''. $autre.'\' AND '.
|
|
'date=\''. $ligne[1].'\' AND '.
|
|
'open='. $ligne[2].' AND '.
|
|
'high='. $ligne[3].' AND '.
|
|
'low='. $ligne[4].' AND '.
|
|
'close='. $ligne[5].' AND '.
|
|
'volume='. $ligne[6]);
|
|
$deja=$ret[0][0];
|
|
if (!$deja) {
|
|
$traite++;*/
|
|
$tabInsert=array( 'lstCode'=>$lstCode,
|
|
'lstNom'=>$lstNom,
|
|
'isin'=>$isin,
|
|
'autre'=>$autre,
|
|
'date'=>date('Ymd'),
|
|
'nom'=>$ligne[1],
|
|
//'sicovam'=>$ligne[2],
|
|
'ticker'=>$ligne[2],
|
|
);
|
|
if (!$iDb2->insert('bourse_listes', $tabInsert))
|
|
if (mysql_errno()<>1062)
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : MySql n°'. mysql_errno() .' : '. mysql_error() . EOL);
|
|
else $error++;
|
|
}
|
|
//else $ntraite++;
|
|
$message=date ('Y/m/d - H:i:s') ." - Liste \"$lstNom\" (code=$lstCode) : $nbLignes valeurs chargées".EOL;
|
|
echo $message;
|
|
$strMailInfo.=$message;
|
|
|
|
}
|
|
@fclose($fp);
|
|
//echo date('Y/m/d - H:i:s') .' - '. ($ntraite+$error) .' cotations déjà en base dont '.$error.' erreur(s) !'.EOL;
|
|
//echo date('Y/m/d - H:i:s') .' - '. $traite.' / '. ($nbLignes-2) .' cours téléchargés.'. EOL;
|
|
sendMail('webmaster@scores-decisions.com', 'support@scores-decisions.com,ylenaour@scores-decisions.com', 'Chargement des compositions des indices boursiers', $strMailInfo);
|
|
}
|
|
|
|
if ($getIPO) {
|
|
$page=getUrl(URL_BOURSE_IPO);
|
|
$body=$page['body'];
|
|
file_put_contents('/root/ipo.txt',$body);
|
|
}
|
|
|
|
if ($isinHisto) {
|
|
$ntraite=$traite=$error=0;
|
|
$heure=1735; // Heure de cloture (maximale)
|
|
if ($isinHisto===true) {
|
|
echo date('Y/m/d - H:i:s') .' - Récupération de la liste des cours à la clôture sur Euronext...'.EOL;
|
|
$tabLibMic=array( 'Marché Libre Paris' => 'XMLI',
|
|
'Marché Libre Paris' => 'XMLI',
|
|
'NYSE Alternext Paris' => 'ALXP',
|
|
'NYSE Euronext Paris' => 'XPAR',
|
|
'NYSE Euronext Brussels' => 'XBRU',
|
|
'NYSE Euronext Amsterdam,Paris' => 'XAMS,XPAR',
|
|
'NYSE Euronext Brussels,Paris' => 'XBRU,XPAR',
|
|
'NYSE Euronext Paris,Brussels' => 'XPAR,XBRU',
|
|
'NYSE Alternext Brussels,Paris' => 'ALXB,ALXP',
|
|
'NYSE Alternext Paris,Brussels' => 'ALXP,ALXB',
|
|
'NYSE Euronext Paris,Amsterdam' => 'XPAR,XAMS',
|
|
'NYSE Euronext Paris,London' => 'XPAR,XLON',
|
|
'NYSE Euronext Paris,Amsterdam,Brussels'=> 'XPAR,XAMS,XBRU',
|
|
);
|
|
if (!file_exists(FILENAME_HISTO_NYX) || date ('Ymd',filemtime(FILENAME_HISTO_NYX))<>date('Ymd')) {
|
|
$postData=array('format'=>2,
|
|
'layout'=>2,
|
|
'decimal_separator'=>1,
|
|
'date_format'=>1,
|
|
'op'=>'Go',
|
|
'form_build_id'=>'form-a2a3c103379768c6c9c5d0b2f765a5f3',
|
|
'form_id'=>'nyx_download_form');
|
|
$page=getUrl(URL_BOURSE_HISTO_NYX, ''/*$cookie*/, $postData);
|
|
$body=$page['body'];
|
|
// print_r($page);
|
|
file_put_contents(FILENAME_HISTO_NYX,$body);
|
|
}
|
|
$tabLignes=file(FILENAME_HISTO_NYX);
|
|
$nbLignes=count($tabLignes);
|
|
$nbAccesDetailMarche=$nbAccesDetailSociete=$iLigneOk=0;
|
|
echo date('Y/m/d - H:i:s') ." - Nombre de valeurs : $nbLignes".EOL;
|
|
foreach ($tabLignes as $iLigne=>$ligne) {
|
|
//echo "$iLigne $ligne".EOL;
|
|
if ($iLigne==0 && trim($ligne)<>'"Nom";"ISIN";"Symbole";"Marché";"Trading Currency";"Ouvert";"Haut";"Bas";"Dernier";"Last Date/Time";"Time Zone";"Volume";"Capitaux"')
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne, libellés CSV différents de ceux attendus '.EOL);
|
|
elseif ($iLigne>0) {
|
|
$ligne=explode(';', str_replace('"','',$ligne));
|
|
$nomAction=$ligne[0];
|
|
$isin=$ligne[1];
|
|
$symbole=$ligne[2];
|
|
$libMarche=$ligne[3];
|
|
$devise=$ligne[4];
|
|
$open=$ligne[5];
|
|
$high=$ligne[6];
|
|
$low=$ligne[7];
|
|
$close=$ligne[8];
|
|
//echo "$isin\t$nomAction\t";
|
|
if (substr($isin,0,2)<>'FR' && strpos(strtoupper($libMarche),'PARIS')===false) {
|
|
//echo "(ignoré)".EOL;
|
|
continue;
|
|
} elseif ($open=='-' && $high=='-' && $low=='-' && $close=='-') {
|
|
//echo "(ignoré)".EOL;
|
|
continue;
|
|
}
|
|
$iLigneOk++;
|
|
$dateYmd=WDate::dateT('d/m/Y','Y-m-d', substr($ligne[9],0,10));
|
|
$dateYmdHis=$dateYmd.substr($ligne[9],10,6).':00';
|
|
$timeZone=$ligne[10];
|
|
$volume=$ligne[11];
|
|
|
|
// Récupération du siren associé à cet isin
|
|
$siren=@$iBourse->getCodeSiren($isin)*1;
|
|
|
|
if (!isset($tabLibMic[$libMarche])) die("Code MIC non trouvé pour '$libMarche'=>'',".EOL);
|
|
$mic=$tabLibMic[$libMarche];
|
|
|
|
$tabSociete=array();
|
|
$ret=$iDb2->select( 'bourse_isin',
|
|
'siren, raisonSociale, code_mnemo, code_isin, mic, code_icb, dateIntroduction, nombreTitres, eligibleSRD, eligiblePEA, marche,
|
|
activiteDet, activiteDetSrc, activiteDetDat*1 AS activiteDetDat',
|
|
"code_isin='$isin'", false, MYSQL_ASSOC);
|
|
if (!isset($ret[0]['code_isin'])) {
|
|
$tabInsert=array( 'code_isin' => $isin,
|
|
'raisonSociale' => $nomAction,
|
|
'code_mnemo' => $symbole,
|
|
'siren' => $siren,
|
|
'mic' => $mic,
|
|
'dernierCours' => $dateYmdHis,
|
|
'dateInsert' => date('YmdHis'),
|
|
'idInsert' => 0,
|
|
);
|
|
$iDb2->insert('bourse_isin', $tabInsert, false);
|
|
//echo $dateYmdHis.mysql_error().EOL;
|
|
echo "$isin\t$siren\t$siren2\t$nomAction\t$symbole\t$mic\t$libMarche\t".$ligne[9]."\tAJOUT".EOL;
|
|
} else {
|
|
$tabSociete=$ret[0];
|
|
$siren2=$tabSociete['siren']*1;
|
|
echo "$isin\t$siren\t$siren2\t$nomAction\t$symbole\t$mic\t$libMarche\t".$ligne[9].EOL;
|
|
//print_r($tabSociete);
|
|
$tabUpdate=array('dernierCours' => $dateYmdHis);
|
|
if ($tabSociete['raisonSociale']<>$nomAction) $tabUpdate['raisonSociale']=$nomAction;
|
|
if ($tabSociete['code_mnemo']<>$symbole) $tabUpdate['code_mnemo']=$symbole;
|
|
if ($siren>0 && $siren2<>$siren) $tabUpdate['siren']=$siren;
|
|
elseif ($siren2>0 && $siren2<>$siren) die('Siren différents'.EOL);
|
|
if ($tabSociete['mic']<>$mic) $tabUpdate['mic']=$mic;
|
|
|
|
$iDb2->update('bourse_isin', $tabUpdate, "code_isin='$isin'", false);
|
|
//echo $dateYmdHis.mysql_error().EOL;
|
|
}
|
|
|
|
if (@$tabSociete['code_icb']==0 || @$tabSociete['dateIntroduction']=='0000-00-00' || @$tabSociete['nombreTitres']==0 ||
|
|
@$tabSociete['eligibleSRD']=='-' || @$tabSociete['eligiblePEA']=='-' || @$tabSociete['marche']=='') {
|
|
// Mise à jour via EURONEXT
|
|
$page=getUrl("https://europeanequities.nyx.com/fr/factsheet-ajax?instrument_id=$isin-$mic&instrument_type=equities");
|
|
if ($page['code']==200) {
|
|
$nbAccesDetailMarche++;
|
|
$body=$page['body'];
|
|
|
|
$tabUpdate=array();
|
|
$codeIcb=substr(htm2txt(@getTextInHtml($body, "<div><span>SousSecteur</span>", '<strong>', '</strong>')),0,4)*1;
|
|
if ($codeIcb>0) $tabUpdate['code_icb']=$codeIcb;
|
|
$dateIntro=WDate::dateT('d Men Y','Ymd', htm2txt(@getTextInHtml($body, "<span>Date d'introduction</span>", '<strong>', '</strong>')));
|
|
if ($dateIntro>19000101) $tabUpdate['dateIntroduction']=$dateIntro;
|
|
$nbTitres=str_replace(',','',htm2txt(@getTextInHtml($body, "<span>Nombre total de titres</span>", '<strong>', '</strong>')))*1;
|
|
if ($nbTitres>0) $tabUpdate['nombreTitres']=$nbTitres;
|
|
$eligiblePea=$eligibleSrd=$libMarche2='-';
|
|
// PEA
|
|
if (preg_match('/<strong>Eligible to PEA<\/strong>/Uis', $body)) $eligiblePea='O';
|
|
if (preg_match('/<strong>Not eligible to PEA<\/strong>/Uis', $body)) $eligiblePea='N';
|
|
elseif (preg_match('/<div><span>Eligibilit\D{1,2} PEA<\/span>\s+<strong>Not provided<\/strong>/Uis', $body)) $eligiblePea='';
|
|
elseif (preg_match('/<div><span>Eligibilit\D{1,2} PEA<\/span>\s+<strong>-<\/strong>/Uis', $body)) $eligiblePea='';
|
|
// SRD
|
|
if (preg_match('/neither eligible for the SRD/Uis', $body)) $eligibleSrd='N';
|
|
elseif (preg_match('/<strong>Instrument eligible for the SRD/Uis', $body)) $eligibleSrd='O';
|
|
elseif (preg_match('/<div><span>Eligibilit\D{1,2} SRD<\/span>\s+<strong>-<\/strong>/Uis', $body)) $eligibleSrd='';
|
|
// Type de marché
|
|
if (preg_match('/<span>Alternext private placement<\/span>/Uis', $body)) $libMarche2='Alternext private placement';
|
|
elseif (preg_match('/<span>Alternext public offering<\/span>/Uis', $body)) $libMarche2='Alternext public offering';
|
|
elseif (preg_match('/<span>Foreign compartment<\/span>/Uis', $body)) $libMarche2='Compartiment Etranger';
|
|
elseif (preg_match('/<strong>Compartment A \(Large Cap\)<\/strong>/Uis', $body)) $libMarche2='Eurolist compartiment A';
|
|
elseif (preg_match('/<strong>Compartment B \(Mid Cap\)<\/strong>/Uis', $body)) $libMarche2='Eurolist compartiment B';
|
|
elseif (preg_match('/<strong>Compartment C \(Small Cap\)<\/strong>/Uis', $body)) $libMarche2='Eurolist compartiment C';
|
|
elseif (preg_match('/<span>Delisted from regulated markets<\/span>/Uis', $body)) $libMarche2='Eurolist compartiment C';
|
|
elseif (preg_match('/<div><span>-<\/span>\s+<strong>-<\/strong><\/div>\s+<(?:\/|)div>/Uis', $body)) $libMarche2='Valeurs Radiées de Marchés Réglementés';
|
|
|
|
if ($eligiblePea=='-' || $eligibleSrd=='-' || $libMarche2=='-')
|
|
die("$body [ $eligiblePea / $eligibleSrd / $libMarche2 ]".EOL);
|
|
|
|
if ($eligiblePea=='') $eligiblePea='-';
|
|
$tabUpdate['eligiblePEA']=$eligiblePea;
|
|
|
|
if ($eligibleSrd=='') $eligibleSrd='-';
|
|
$tabUpdate['eligibleSRD']=$eligibleSrd;
|
|
|
|
$tabUpdate['marche']=$libMarche2;
|
|
/*
|
|
1 Compartiment Professionnel
|
|
2 Compartiment spécial
|
|
125 Eurolist compartiment A
|
|
325 Eurolist compartiment C
|
|
18 Eurolist hors zone Euro
|
|
6 Eurolist zone Euro
|
|
5 Main Market
|
|
1 Main Standard
|
|
1 MAR LIBRE OTC
|
|
258 Marché libre
|
|
1 MR - Compartiment C
|
|
1 Prime Standard
|
|
*/
|
|
$iDb2->update('bourse_isin', $tabUpdate, "code_isin='$isin'", false);
|
|
echo "$isin\t$siren\t$siren2\t$nomAction\t$symbole\t$mic\t$libMarche\t".$ligne[9].EOL;
|
|
print_r($tabUpdate);
|
|
}
|
|
//randsleep(7,21);
|
|
}
|
|
|
|
|
|
$tabSrc=array('Cofisem'=>3000);
|
|
if (@$tabSociete['activiteDet']=='' || @$tabSociete['activiteDetDat']<=19800101) {
|
|
// Mise à jour via EURONEXT
|
|
$page=getUrl("https://europeanequities.nyx.com/fr/nyx-company-profile/ajax?instrument_id=$isin-$mic");
|
|
if ($page['code']==200) {
|
|
$nbAccesDetailSociete++;
|
|
$body=$page['body'];
|
|
echo $body.EOL;
|
|
|
|
$tabUpdate=array();
|
|
$activiteDet=@getTextInHtml($body, '<div id="company-profile-description" class="block company-profile-section">', '<div class="detail">', '<div id="company-profile-key-executives"');
|
|
$tmpUpdate=@getTextInHtml($activiteDet, '<div class="last-updated">', 'Source:', '</div>');
|
|
$tabTmp=explode(' - Last Update: ', $tmpUpdate);
|
|
$activiteDetSrc=$tabTmp[0];
|
|
$activiteDetDat=WDate::dateT('d Men Y','Ymd', $tabTmp[1]);
|
|
$activiteDet=utf8_decode(htm2txt(preg_replace('/<div class="last-updated">.*/','',$activiteDet)));
|
|
|
|
//die($activiteDet.EOL.$tmpUpdate.EOL.$activiteDetSrc.EOL.$activiteDetDat.EOL);
|
|
|
|
if ($activiteDet<>'') $tabUpdate['activiteDet']=$activiteDet;
|
|
if ($activiteDetSrc<>'') $tabUpdate['activiteDetSrc']=@$tabSrc[$activiteDetSrc];
|
|
if ($activiteDetDat>19000101) $tabUpdate['activiteDetDat']=$activiteDetDat;
|
|
|
|
$iDb2->update('bourse_isin', $tabUpdate, "code_isin='$isin'", false);
|
|
echo "$isin\t$siren\t$siren2\t$nomAction\t$symbole\t$mic\t$libMarche\t".$ligne[9].EOL;
|
|
print_r($tabUpdate);
|
|
}
|
|
//randsleep(7,21);
|
|
}
|
|
|
|
if($siren<1000) //echo "\t$nomAction\t$mic\t$libMarche".EOL;
|
|
echo "$isin\t$siren\t$siren2\t$nomAction\t$symbole\t$mic\t$libMarche\t".$ligne[9]."\tPas de SIREN".EOL;
|
|
|
|
$ret=$iDb2->select('bourse_cours', 'count(*)', "isin='$isin' AND autre='' AND date='$dateYmd' AND heure=$heure AND
|
|
open=$open AND high=$high AND low=$low AND close=$close AND volume=$volume", false);
|
|
$deja=$ret[0][0];
|
|
if (!$deja) {
|
|
$traite++;
|
|
$tabInsert=array( 'isin'=>$isin,
|
|
'autre'=>'',
|
|
'date'=>$dateYmd,
|
|
'open'=>$open,
|
|
'high'=>$high,
|
|
'low'=>$low,
|
|
'close'=>$close,
|
|
'volume'=>$volume,
|
|
'heure'=>$heure,
|
|
'devise'=>$devise,
|
|
);
|
|
if (!$iDb2->insert('bourse_cours', $tabInsert))
|
|
if (mysql_errno()<>1062)
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : MySql n°'. mysql_errno() .' : '. mysql_error() . EOL);
|
|
else $error++;
|
|
}
|
|
else $ntraite++;
|
|
}
|
|
}
|
|
|
|
echo date('Y/m/d - H:i:s') ." - $nbAccesDetailMarche/$iLigneOk accès NYX sur les données marché.".EOL;
|
|
echo date('Y/m/d - H:i:s') ." - $nbAccesDetailSociete/$iLigneOk accès NYX sur les données société.".EOL;
|
|
|
|
unlink(FILENAME_HISTO_NYX);
|
|
|
|
$nbLignes=$iLigne;
|
|
} else {
|
|
$mic='';
|
|
$isin=$isinHisto;
|
|
$dateFinUnix=gmmktime(0, 0, 0, date('m'), date('d')-1, date('Y')).'000';
|
|
$ret=$iDb2->select( 'bourse_isin',
|
|
'siren, raisonSociale, code_mnemo, code_isin, mic, code_icb, dateIntroduction, dateIntroduction*1 AS dateIntroYmd,
|
|
nombreTitres, eligibleSRD, eligiblePEA, marche, activiteDet, activiteDetSrc, activiteDetDat*1 AS activiteDetDat',
|
|
"code_isin='$isin'", false, MYSQL_ASSOC);
|
|
if (isset($ret[0]['code_isin'])) {
|
|
$tabSociete=$ret[0];
|
|
if (strlen($tabSociete['mic'])>3) $mic=substr($tabSociete['mic'],0,4); // On prend le 1er MIC
|
|
$dateDebUnix=gmmktime(0, 0, 0, 1, 1, 2009).'000';
|
|
//$dateDebUnix=gmmktime(0, 0, 0, 5, 1, 2013).'000';
|
|
die("isin=$isin, mic='$mic', dateIntro=$dateIntroYmd".EOL);
|
|
}
|
|
if ($mic=='') die("Pas de MIC pour $isin".EOL);
|
|
|
|
$url=URL_BOURSE_ISIN_H."&typedate=dmy&separator=point&mic=$mic&isin=$isin&namefile=Price_Data_Historical&from=$dateDebUnix&to=$dateFinUnix&adjusted=1&base=0"; // &name=ATARI
|
|
$page=getUrl($url);
|
|
|
|
$body=$page['body'];
|
|
file_put_contents("/tmp/getIsin-Histo-$isin.csv",$body);
|
|
$tabLignes=file("/tmp/getIsin-Histo-$isin.csv");
|
|
foreach ($tabLignes as $iLigne=>$ligne) {
|
|
//echo "$iLigne $ligne".EOL;
|
|
if ($iLigne==0 && trim($ligne)<>'"Historical price chart data"')
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : Première ligne différente de "Historical price chart data"'.EOL);
|
|
elseif ($iLigne==1 && substr($ligne,0,7)<>'"Date: ')
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : Deuxième ligne différente de "Date: ..."'.EOL);
|
|
elseif ($iLigne==2 && trim($ligne)<>'""')
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : 3ème ligne différente de ""'.EOL);
|
|
elseif ($iLigne==3 && trim($ligne)<>'"ISIN","MIC","Date","Open","High","Low","Close","Number of Shares","Number of Trades","Turnover","Currency"')
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : 4ème ligne, libellés CSV différents de ceux attendus '.EOL);
|
|
elseif ($iLigne>3) {
|
|
$ligne=explode(',', str_replace('"','',$ligne));
|
|
$dateYmd=WDate::dateT('d/m/Y','Y-m-d', $ligne[2]);
|
|
$open=$ligne[3]/100;
|
|
$high=$ligne[4]/100;
|
|
$low=$ligne[5]/100;
|
|
$close=$ligne[6]/100;
|
|
$volume=str_replace('.','',$ligne[7]);
|
|
$devise=$ligne[10];
|
|
$ret=$iDb2->select('bourse_cours', 'count(*)', "isin='$isin' AND autre='' AND date='$dateYmd' AND heure=$heure AND
|
|
open=$open AND high=$high AND low=$low AND close=$close AND volume=$volume", false);
|
|
$deja=$ret[0][0];
|
|
if (!$deja) {
|
|
$traite++;
|
|
$tabInsert=array( 'isin'=>$isin,
|
|
'autre'=>'',
|
|
'date'=>$dateYmd,
|
|
'open'=>$open,
|
|
'high'=>$high,
|
|
'low'=>$low,
|
|
'close'=>$close,
|
|
'volume'=>$volume,
|
|
'heure'=>$heure,
|
|
'devise'=>$devise,
|
|
);
|
|
if (!$iDb2->insert('bourse_cours', $tabInsert))
|
|
if (mysql_errno()<>1062)
|
|
die(date ('Y/m/d - H:i:s') .' - ERREUR : MySql n°'. mysql_errno() .' : '. mysql_error() . EOL);
|
|
else $error++;
|
|
}
|
|
else $ntraite++;
|
|
}
|
|
}
|
|
$nbLignes=$iLigne-3;
|
|
}
|
|
|
|
/*
|
|
"Historical price chart data"
|
|
"Date: 01/01/2000 - 20/05/2013"
|
|
""//Date, Ouvert, Haut, Bas, Fermer, Nombre de titres, Capitaux
|
|
"ISIN","MIC","Date","Open","High","Low","Close","Number of Shares","Number of Trades","Turnover","Currency"
|
|
"FR0010478248","NYSE Euronext Paris","03/01/2000","84065077","86208643","81548717","81548717","19.419","3.403","16.426.84397","EUR"
|
|
*/
|
|
echo date('Y/m/d - H:i:s') .' - '. ($ntraite+$error) .' cotations déjà en base dont '.$error.' erreur(s) !'.EOL;
|
|
$strMailInfo.=date('Y/m/d - H:i:s') .' - '. ($ntraite+$error) .' cotations déjà en base dont '.$error.' erreur(s) !'.EOL;
|
|
echo date('Y/m/d - H:i:s') .' - '. $traite.' / '. ($nbLignes-2) .' cours téléchargés.'. EOL;
|
|
|
|
}
|
|
|
|
echo date('Y/m/d - H:i:s') .' - FIN du script.'. EOL;
|
|
?>
|