Separate file for pledge data.
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
|
||||
$options = getopt("", ["candidates-files:"]);
|
||||
$options = getopt("", ["pledges-files:"]);
|
||||
|
||||
if (isset($options['candidates-files'])) {
|
||||
$candidatesFiles = $options['candidates-files'];
|
||||
if (isset($options['pledges-files'])) {
|
||||
$pledges_files = $options['pledges-files'];
|
||||
} else {
|
||||
error_log("Error: Missing required option '--candidates-files'.");
|
||||
error_log("Error: Missing required option '--pledges-files'.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$files = explode(" ", $candidatesFiles);
|
||||
$files = explode(" ", $pledges_files);
|
||||
|
||||
$candidateData = [];
|
||||
$candidate_data = [];
|
||||
foreach ($files as $key => $file) {
|
||||
$config_file = dirname($file)."/config.json";
|
||||
$config_string = file_get_contents($config_file);
|
||||
@@ -23,7 +23,9 @@ foreach ($files as $key => $file) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (($handle = fopen($file, "r")) !== FALSE) {
|
||||
$candidate_file = dirname($file)."/candidates.csv";
|
||||
|
||||
if (($handle = fopen($candidate_file, "r")) !== FALSE) {
|
||||
$headers = fgetcsv($handle);
|
||||
while (($data = fgetcsv($handle)) !== FALSE) {
|
||||
$candidate = [];
|
||||
@@ -33,17 +35,33 @@ foreach ($files as $key => $file) {
|
||||
}
|
||||
$candidate['Council'] = $config['councilName'];
|
||||
$candidate['Path'] = dirname($file);
|
||||
$candidateData[] = $candidate;
|
||||
$candidate_data[$candidate['Candidate Name']] = $candidate;
|
||||
}
|
||||
fclose($handle);
|
||||
} else {
|
||||
error_log('Error opening candidates file');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (($handle = fopen($file, "r")) !== FALSE) {
|
||||
$headers = fgetcsv($handle);
|
||||
while (($data = fgetcsv($handle)) !== FALSE) {
|
||||
$candidate = [];
|
||||
foreach ($headers as $key => $value) {
|
||||
$candidate[$value] = $data[$key];
|
||||
}
|
||||
$candidate_data[$candidate['Candidate Name']]['Pledge'] =
|
||||
$candidate['Pledge'];
|
||||
}
|
||||
fclose($handle);
|
||||
} else {
|
||||
error_log('Error opening pledges file');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Select people who have taken the pledge */
|
||||
$pledgeCandidates = array_filter($candidateData, function ($candidate) {
|
||||
$pledgeCandidates = array_filter($candidate_data, function ($candidate) {
|
||||
return $candidate['Pledge'] === 'y';
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# If this runs as a cron job - might want to limit the number of revisions wordpress stores:
|
||||
# If this runs as a cron job - might want to limit the number of revisions
|
||||
# wordpress stores:
|
||||
# wp-config.php:
|
||||
# define( 'WP_POST_REVISIONS', 3 );
|
||||
|
||||
@@ -12,14 +13,14 @@
|
||||
|
||||
DATA_PATH="../spl-data"
|
||||
|
||||
candidates_files=()
|
||||
pledges_files=()
|
||||
for folder in "$DATA_PATH"/*; do
|
||||
if test -f "$folder"/candidates.csv; then
|
||||
candidates_files+=("$folder"/candidates.csv)
|
||||
if test -f "$folder"/pledges.csv; then
|
||||
pledges_files+=("$folder"/pledges.csv)
|
||||
fi
|
||||
done
|
||||
|
||||
pledge_sed=$(php pledge-update/main.php --candidates-files "${candidates_files[*]}")
|
||||
pledge_sed=$(php pledge-update/main.php --pledges-files "${pledges_files[*]}")
|
||||
|
||||
content=$(sed "$pledge_sed" ../spl-data/movie-homepage)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user