Select 9 random candidates for pledge area and generate sed commands.

This commit is contained in:
Kim Taylor
2024-09-08 22:25:14 +10:00
parent ca0bab5071
commit 18910638a1

View File

@@ -19,7 +19,7 @@ foreach ($files as $key => $file) {
if ($config_string !== FALSE) { if ($config_string !== FALSE) {
$config = json_decode($config_string, true); $config = json_decode($config_string, true);
} else { } else {
error_log('Error opening config.json'); error_log("Error opening config.json.");
exit(1); exit(1);
} }
@@ -32,6 +32,7 @@ foreach ($files as $key => $file) {
$candidate[$value] = $data[$key]; $candidate[$value] = $data[$key];
} }
$candidate['Council'] = $config['councilName']; $candidate['Council'] = $config['councilName'];
$candidate['Path'] = dirname($file);
$candidateData[] = $candidate; $candidateData[] = $candidate;
} }
fclose($handle); fclose($handle);
@@ -41,10 +42,39 @@ foreach ($files as $key => $file) {
} }
} }
/* Select people who have taken the pledge */
$pledgeCandidates = array_filter($candidateData, function ($candidate) { $pledgeCandidates = array_filter($candidateData, function ($candidate) {
return $candidate['Pledge'] === 'y'; return $candidate['Pledge'] === 'y';
}); });
print_r($pledgeCandidates); /* Select 9 random candidates */
$pledgeKeys = array_rand($pledgeCandidates, 9);
shuffle($pledgeKeys);
$i = 0;
foreach ($pledgeKeys as $key) {
$media_desc = $pledgeCandidates[$key]['Path']."/".
$pledgeCandidates[$key]['Picture'].".json";
$media_string = file_get_contents($media_desc);
if ($media_string !== FALSE) {
$media = json_decode($media_string, true);
} else {
error_log("Error opening image descriptor.");
exit(1);
}
$image_url = $media['url'];
echo "s|pledge_img_".$i."|".$image_url."|\n";
echo "s|pledge_string_".$i."|";
echo $pledgeCandidates[$key]['Candidate Name'].
" (".
$pledgeCandidates[$key]['Council'].
") has taken the pledge!|\n";
$i++;
}
exit(0); exit(0);