Add initial support for reading candidate data from a CSV file
This commit is contained in:
@@ -18,8 +18,29 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Convert CSV into an array of dictionaries. Use the header as the key in the dictionary.
|
||||
$candidates = [];
|
||||
if (isset($argv[2])) {
|
||||
if (($handle = fopen($argv[2], "r")) !== FALSE) {
|
||||
$headers = fgetcsv($handle);
|
||||
while (($data = fgetcsv($handle)) !== FALSE) {
|
||||
$candidate = [];
|
||||
foreach ($headers as $key => $value) {
|
||||
$candidate[$value] = $data[$key];
|
||||
}
|
||||
$candidates[] = $candidate;
|
||||
}
|
||||
fclose($handle);
|
||||
} else {
|
||||
error_log('Error opening CSV');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check that candidates were read successfully??
|
||||
|
||||
$renderer = new SPLPageRenderer();
|
||||
$pageContent = $renderer->renderCouncilPage($config);
|
||||
$pageContent = $renderer->renderCouncilPage($config, $candidates);
|
||||
if ($pageContent === null) {
|
||||
exit(2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user