Generate all-council page with bold text for LGAs with data.
This commit is contained in:
50
lga-page.php
Normal file
50
lga-page.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$options = getopt("", ["candidates-files:", "lga-files:"]);
|
||||||
|
|
||||||
|
if (isset($options['candidates-files'])) {
|
||||||
|
$candidates_files = explode(" ", $options['candidates-files']);
|
||||||
|
} else {
|
||||||
|
error_log("Error: Missing required option '--candidates-files'.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['lga-files'])) {
|
||||||
|
$lga_files = explode(" ", $options['lga-files']);
|
||||||
|
} else {
|
||||||
|
error_log("Error: Missing required option '--lga-files'.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgas_with_data = [];
|
||||||
|
foreach ($candidates_files as $file) {
|
||||||
|
$lgas_with_data[] = basename(dirname($file));
|
||||||
|
}
|
||||||
|
|
||||||
|
print('<!-- wp:list --> <ul class="wp-block-list">' . "\n");
|
||||||
|
|
||||||
|
foreach ($lga_files as $config_file) {
|
||||||
|
$config_string = file_get_contents($config_file);
|
||||||
|
|
||||||
|
if ($config_string !== FALSE) {
|
||||||
|
$config = json_decode($config_string, true);
|
||||||
|
} else {
|
||||||
|
error_log("Error opening config.json.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_search($config['slug'], $lgas_with_data) === false)
|
||||||
|
$font_weight = 300;
|
||||||
|
else
|
||||||
|
$font_weight = 700;
|
||||||
|
|
||||||
|
print('<!-- wp:list-item {"style":{"typography":{"fontStyle":"normal","fontWeight":"');
|
||||||
|
print($font_weight . '"}}} -->' . "\n");
|
||||||
|
print('<li style="font-style:normal;font-weight:' . $font_weight . '">');
|
||||||
|
print('<a href="' . $config['slug'] . '">' . $config['councilName'] . "</a></li>\n");
|
||||||
|
print('<!-- /wp:list-item -->' . "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
print('</ul> <!-- /wp:list -->');
|
||||||
|
|
||||||
|
exit(0);
|
||||||
25
make-lga-page.sh
Executable file
25
make-lga-page.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script uses the jq, wp, and php commands, make sure they are installed before running this script.
|
||||||
|
|
||||||
|
# The folder containing data for each council.
|
||||||
|
# Includes the list of candidates and any media.
|
||||||
|
DATA_PATH="../spl-data"
|
||||||
|
|
||||||
|
# Iterate over folders in data path
|
||||||
|
candidates_files=()
|
||||||
|
for folder in "$DATA_PATH"/*; do
|
||||||
|
if test -f "$folder"/candidates-generic.csv; then
|
||||||
|
candidates_files+=("$folder"/candidates-generic.csv)
|
||||||
|
elif test -f "$folder"/candidates.csv; then
|
||||||
|
candidates_files+=("$folder"/candidates.csv)
|
||||||
|
fi
|
||||||
|
if test -f "$folder"/config.json; then
|
||||||
|
lga_files+=("$folder"/config.json)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
content=$(php lga-page.php --candidates-files "${candidates_files[*]}" \
|
||||||
|
--lga-files "${lga_files[*]}")
|
||||||
|
|
||||||
|
echo "$content" | wp post update 465 -
|
||||||
Reference in New Issue
Block a user