Skip to content

Instantly share code, notes, and snippets.

@marciuz
Last active May 8, 2017 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciuz/3474ab2b39eadcfd21271a683aa0260d to your computer and use it in GitHub Desktop.
Save marciuz/3474ab2b39eadcfd21271a683aa0260d to your computer and use it in GitHub Desktop.
Generatore di cron per harvest DKAN dati.gov.it
<?php
$sources = 'http://www.dati.gov.it/admin/harvest-sources-export/harvest-sources-datigovit.csv';
$eccezioni = array(
'regione_toscana',
'dati_trentino',
'dati_lombardia',
'comune_di_firenze_annstat',
);
$h = [22, 23, 0, 1, 2, 3, 4, 5, 6];
$hc = 0;
$gg = 1;
$str = '';
$exec = '/usr/local/bin/harvest.sh';
$file = fopen($sources, 'r');
$ahs = [];
while (($line = fgetcsv($file)) !== FALSE) {
if(!in_array($line[1], $eccezioni) && $line[4] != 0) {
$ahs[] = $line[1];
}
else{
$str.='# Disabilitata: ' . $line[1] . "\n";
}
}
fclose($file);
for($i=0;$i<count($ahs);$i++) {
$m = ($i % 2 == 0) ? 10 : 40;
if($hc > count($h)-1) {
$hc=0;
}
if($h[$hc] == 0 && $m==10) $gg++;
$str.= $m . " " . $h[$hc] . " " ." * * ". $gg . "\t" . $exec . "\t". $ahs[$i] ."\n";
if($m==40) $hc++;
}
print $str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment