Use default image for candidates who have signed the ledge, but not provided an image.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
# The folder containing data for each council.
|
||||
# Includes the list of candidates and any media.
|
||||
DATA_PATH="../spl-data"
|
||||
DEFAULT_IMAGE="../spl-data/default.png.json"
|
||||
|
||||
# Iterate over folders in data path
|
||||
candidates_files=()
|
||||
@@ -17,6 +18,7 @@ for folder in "$DATA_PATH"/*; do
|
||||
fi
|
||||
done
|
||||
|
||||
content=$(php pledge-update/pledge-page.php --candidates-files "${candidates_files[*]}")
|
||||
content=$(php pledge-update/pledge-page.php --candidates-files "${candidates_files[*]}" \
|
||||
--default-image $DEFAULT_IMAGE)
|
||||
|
||||
wp post update 12106 --post_content="$content"
|
||||
echo "$content" | wp post update 12106 -
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
function parse_pledge_data($candidates_files) {
|
||||
function parse_pledge_data($candidates_files, $default_image) {
|
||||
$candidate_data = [];
|
||||
foreach ($candidates_files as $key => $file) {
|
||||
$config_file = dirname($file)."/config.json";
|
||||
@@ -19,8 +19,13 @@ function parse_pledge_data($candidates_files) {
|
||||
$candidate = [];
|
||||
$candidate['Pledge'] = 'n';
|
||||
$candidate['Picture'] = "";
|
||||
if (is_array($default_image)) {
|
||||
$candidate['image_url'] = $default_image['url'];
|
||||
$candidate['image_id'] = $default_image['id'];
|
||||
} else {
|
||||
$candidate['image_url'] = "";
|
||||
$candidate['image_id'] = "";
|
||||
}
|
||||
foreach ($headers as $key => $value) {
|
||||
$candidate[$value] = $data[$key];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
require_once("parse_pledge_data.php");
|
||||
require_once("page_renderer.php");
|
||||
|
||||
$options = getopt("", ["candidates-files:"]);
|
||||
$options = getopt("", ["candidates-files:", "default-image:"]);
|
||||
|
||||
if (isset($options['candidates-files'])) {
|
||||
$candidates_files = $options['candidates-files'];
|
||||
@@ -12,7 +12,23 @@ if (isset($options['candidates-files'])) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$candidate_data = parse_pledge_data(explode(" ", $candidates_files));
|
||||
if (isset($options['default-image'])) {
|
||||
$default_image = $options['default-image'];
|
||||
} else {
|
||||
error_log("Error: Missing required option '--default-image'.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$default_image = file_get_contents($default_image);
|
||||
|
||||
if ($default_image !== FALSE) {
|
||||
$default_image = json_decode($default_image, true);
|
||||
} else {
|
||||
error_log("Error opening config.json.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$candidate_data = parse_pledge_data(explode(" ", $candidates_files), $default_image);
|
||||
|
||||
/* Select people who have taken the pledge */
|
||||
$pledgeCandidates = array_filter($candidate_data, function ($candidate) {
|
||||
|
||||
Reference in New Issue
Block a user