Created
February 24, 2015 12:11
-
-
Save paulbeattie/da6c071f90bd893ae666 to your computer and use it in GitHub Desktop.
GCC HH Energy Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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