From ca0bab50719dd4d1c9a566d9f6af08b2a1c54e8e Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sun, 8 Sep 2024 19:26:09 +1000 Subject: [PATCH] Collect data for pledge rotation. --- .gitignore | 1 + pledge-update/main.php | 50 ++++++++++++++++++++++++++++++++++++++++++ update-pledges.sh | 16 +++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 pledge-update/main.php mode change 100644 => 100755 update-pledges.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/pledge-update/main.php b/pledge-update/main.php new file mode 100644 index 0000000..ee009e7 --- /dev/null +++ b/pledge-update/main.php @@ -0,0 +1,50 @@ + $file) { + $config_file = dirname($file)."/config.json"; + $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 (($handle = fopen($file, "r")) !== FALSE) { + $headers = fgetcsv($handle); + while (($data = fgetcsv($handle)) !== FALSE) { + $candidate = []; + $candidate['Pledge'] = 'n'; + foreach ($headers as $key => $value) { + $candidate[$value] = $data[$key]; + } + $candidate['Council'] = $config['councilName']; + $candidateData[] = $candidate; + } + fclose($handle); + } else { + error_log('Error opening candidates file'); + exit(1); + } +} + +$pledgeCandidates = array_filter($candidateData, function ($candidate) { + return $candidate['Pledge'] === 'y'; +}); + +print_r($pledgeCandidates); + +exit(0); diff --git a/update-pledges.sh b/update-pledges.sh old mode 100644 new mode 100755 index 1942745..6ccf4b4 --- a/update-pledges.sh +++ b/update-pledges.sh @@ -1,8 +1,22 @@ #!/bin/bash +# 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 ); + #wp post list --post_type=page #wp post get 426 --field=content > current-homepage #wp post get 1409 --field=content > movie-homepage #wp post create --post_type=page --post_title="test_pledge" movie-homepage +#wp post update 1803 ../spl-data/movie-homepage -wp post update 1803 ../spl-data/movie-homepage +DATA_PATH="../spl-data" + +candidates_files=() +for folder in "$DATA_PATH"/*; do + if test -f "$folder"/candidates.csv; then + candidates_files+=("$folder"/candidates.csv) + fi +done + +php pledge-update/main.php --candidates-files "${candidates_files[*]}"