odea/batch/getDataCSV.php
Michael RICOIS bf4ad53075 Ajout
2011-11-29 15:53:05 +00:00

110 lines
2.5 KiB
PHP

#!/usr/bin/php -q
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$configuration = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini');
Zend_Registry::set('configuration', $configuration);
try {
$opts = new Zend_Console_Getopt(
//Options
array(
'help|?' => "Affiche l'aide.",
'all' => "Charge tout les éléments",
'one' => "Charge un élément",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if(count($opts->getOptions())==0 || isset($opts->help))
{
echo "Charge les données nécessaire à l'applicatioon à partir du webservice.";
echo "\n\n";
echo $opts->getUsageMessage();
echo "\n";
exit;
}
//Utilisateur webservice
define('LOGIN', '');
define('PASSWORD', '');
$args = $opts->getRemainingArgs();
$elements = array('naf');
if ($opts->all || $opts->one){
require_once 'Scores/WsScores.php';
$ws = new WsScores(LOGIN, PASSWORD);
}
if ($opts->all)
{
foreach($elements as $element)
{
$reponse = $ws->getDataCSV($element);
}
} elseif ($opts->one) {
//Vérification
$element = $args[0];
if (!in_array($args[0], $elements)){
echo 'Element inconnu !';
}
$reponse = $ws->getDataCSV($element);
}
//Méthodes interne
function getFichier($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE,TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function saveToDatabase($key, $filename)
{
//Vider la table
$sql = "TRUNCATE $key";
//Sauvegarder toutes les lignes
$cmd = "mysqlimport --ignore-lines=1 --fields-enclosed-by=\\\" --fields-terminated-by=, --user=USERNAME --password=PASSWORD ciblage $filename";
exec($command);
}
?>