Files
spl-tools/pledge-update/homepage.php
2024-09-17 22:02:09 +10:00

43 lines
1.1 KiB
PHP

<?php
require_once("parse_pledge_data.php");
$options = getopt("", ["candidates-files:"]);
if (isset($options['candidates-files'])) {
$candidates_files = $options['candidates-files'];
} else {
error_log("Error: Missing required option '--candidates-files'.");
exit(1);
}
$candidate_data = parse_pledge_data(explode(" ", $candidates_files));
/* Select people who have taken the pledge */
$pledgeCandidates = array_filter($candidate_data, function ($candidate) {
return $candidate['Pledge'] === 'y';
});
/* Select 9 random candidates */
$pledgeKeys = array_rand($pledgeCandidates, 9);
shuffle($pledgeKeys);
$i = 0;
foreach ($pledgeKeys as $key) {
$image_url = $pledgeCandidates[$key]['image_url'];
$image_id = $pledgeCandidates[$key]['image_id'];
echo "s|pledge_img_".$i."|".$image_url."|\n";
echo "s|pledge_id_".$i."|".$image_id."|\n";
echo "s|pledge_string_".$i."|";
echo $pledgeCandidates[$key]['Candidate Name'].
" (".
$pledgeCandidates[$key]['Council'].
") has taken the pledge!|\n";
$i++;
}
exit(0);