diff --git a/pledge-update/main.php b/pledge-update/main.php index 1b7c68c..594084c 100644 --- a/pledge-update/main.php +++ b/pledge-update/main.php @@ -1,17 +1,17 @@ $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'; }); diff --git a/update-pledges.sh b/update-pledges.sh index e07bca2..a8db05a 100755 --- a/update-pledges.sh +++ b/update-pledges.sh @@ -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)