Skip to content

Instantly share code, notes, and snippets.

@paulbeattie
Created February 24, 2015 12:11
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 paulbeattie/da6c071f90bd893ae666 to your computer and use it in GitHub Desktop.
Save paulbeattie/da6c071f90bd893ae666 to your computer and use it in GitHub Desktop.
GCC HH Energy Data
<?php
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
$pfiles = scandir(getcwd());
$files = array();
foreach ($pfiles as $file) {
if (endsWith($file, '.csv')) {
$files[] = $file;
}
}
$outar = array();
foreach ($files as $file) {
$ar = array();
$ar['url'] = "http://dashboard.glasgow.gov.uk/ckansupport/stcenergy/$file";
$ds = str_replace('.csv', '', $file);
$ar['date'] = $ds;
$size = filesize($file);
$ar['size'] = $size;
$outar[] = $ar;
}
$os = json_encode($outar);
// Since JSON_UNESCAPED_SLASHES isn't in php 5.3 we need to remove them manually.
$os = str_replace('\\/', '/', $os);
header('Content-type: application/json');
die($os);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment