From 0f89ddf779ce9340d2ec08db0353f0a3d33f81cd Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Tue, 17 Sep 2024 21:19:26 +1000 Subject: [PATCH 1/8] Use pledges.csv files as override of candidates.csv files. --- pledge-update/main.php | 20 +++++++++++--------- update-pledges.sh | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pledge-update/main.php b/pledge-update/main.php index 594084c..b9efc7c 100644 --- a/pledge-update/main.php +++ b/pledge-update/main.php @@ -1,15 +1,15 @@ $file) { @@ -23,9 +23,7 @@ foreach ($files as $key => $file) { exit(1); } - $candidate_file = dirname($file)."/candidates.csv"; - - if (($handle = fopen($candidate_file, "r")) !== FALSE) { + if (($handle = fopen($file, "r")) !== FALSE) { $headers = fgetcsv($handle); while (($data = fgetcsv($handle)) !== FALSE) { $candidate = []; @@ -43,7 +41,11 @@ foreach ($files as $key => $file) { exit(1); } - if (($handle = fopen($file, "r")) !== FALSE) { + $pledges_file = dirname($file)."/pledges.csv"; + + if (!file_exists($pledges_file)) continue; + + if (($handle = fopen($pledges_file, "r")) !== FALSE) { $headers = fgetcsv($handle); while (($data = fgetcsv($handle)) !== FALSE) { $candidate = []; diff --git a/update-pledges.sh b/update-pledges.sh index 9283f8a..7385994 100755 --- a/update-pledges.sh +++ b/update-pledges.sh @@ -13,14 +13,14 @@ DATA_PATH="../spl-data" -pledges_files=() +candidates_files=() for folder in "$DATA_PATH"/*; do - if test -f "$folder"/pledges.csv; then - pledges_files+=("$folder"/pledges.csv) + if test -f "$folder"/candidates.csv; then + candidates_files+=("$folder"/candidates.csv) fi done -pledge_sed=$(php pledge-update/main.php --pledges-files "${pledges_files[*]}") +pledge_sed=$(php pledge-update/main.php --candidates-files "${candidates_files[*]}") content=$(sed "$pledge_sed" ../spl-data/movie-homepage) From 1412c268b5f10672b80395fcd31d76218a38087d Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Tue, 17 Sep 2024 22:02:09 +1000 Subject: [PATCH 2/8] Move pledge data parsing to separate file. --- make-pledge-page.sh | 19 ++++++ pledge-update/homepage.php | 42 ++++++++++++ pledge-update/main.php | 102 ---------------------------- pledge-update/parse_pledge_data.php | 73 ++++++++++++++++++++ pledge-update/pledge-page.php | 44 ++++++++++++ update-pledges.sh | 2 +- 6 files changed, 179 insertions(+), 103 deletions(-) create mode 100755 make-pledge-page.sh create mode 100644 pledge-update/homepage.php delete mode 100644 pledge-update/main.php create mode 100644 pledge-update/parse_pledge_data.php create mode 100644 pledge-update/pledge-page.php diff --git a/make-pledge-page.sh b/make-pledge-page.sh new file mode 100755 index 0000000..b953b84 --- /dev/null +++ b/make-pledge-page.sh @@ -0,0 +1,19 @@ +#!/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.csv; then + candidates_files+=("$folder"/candidates.csv) + fi +done + +content=$(php pledge-update/pledge-page.php --candidates-files "${candidates_files[*]}") + +echo $content; diff --git a/pledge-update/homepage.php b/pledge-update/homepage.php new file mode 100644 index 0000000..4c941b2 --- /dev/null +++ b/pledge-update/homepage.php @@ -0,0 +1,42 @@ + $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']; - $candidate['Path'] = dirname($file); - $candidate_data[$candidate['Candidate Name']] = $candidate; - } - fclose($handle); - } else { - error_log('Error opening candidates file'); - exit(1); - } - - $pledges_file = dirname($file)."/pledges.csv"; - - if (!file_exists($pledges_file)) continue; - - if (($handle = fopen($pledges_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($candidate_data, function ($candidate) { - return $candidate['Pledge'] === 'y'; -}); - -/* Select 9 random candidates */ -$pledgeKeys = array_rand($pledgeCandidates, 9); -shuffle($pledgeKeys); - -$i = 0; -foreach ($pledgeKeys as $key) { - $media_desc = $pledgeCandidates[$key]['Path']."/". - $pledgeCandidates[$key]['Picture'].".json"; - $media_string = file_get_contents($media_desc); - - if ($media_string !== FALSE) { - $media = json_decode($media_string, true); - } else { - error_log("Error opening image descriptor."); - exit(1); - } - - $image_url = $media['url']; - $image_id = $media['id']; - - echo "s|pledge_img_".$i."|".$image_url."|\n"; - echo "s|pledge_id_".$i."|".$image_id."|\n"; - - echo "s|pledge_string_".$i."|"; - echo $pledgeCandidates[$key]['Candidate Name']. - " (". - $pledgeCandidates[$key]['Council']. - ") has taken the pledge!|\n"; - - $i++; -} - -exit(0); diff --git a/pledge-update/parse_pledge_data.php b/pledge-update/parse_pledge_data.php new file mode 100644 index 0000000..3cdcf71 --- /dev/null +++ b/pledge-update/parse_pledge_data.php @@ -0,0 +1,73 @@ + $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'; + $candidate['Picture'] = ""; + $candidate['image_url'] = ""; + $candidate['image_id'] = ""; + foreach ($headers as $key => $value) { + $candidate[$value] = $data[$key]; + } + $candidate['Council'] = $config['councilName']; + $candidate['Path'] = dirname($file); + $media_desc = $candidate['Path']."/". + $candidate['Picture'].".json"; + if (file_exists($media_desc)) { + $media_string = file_get_contents($media_desc); + if ($media_string !== FALSE) { + $media = json_decode($media_string, true); + } else { + error_log("Error opening image descriptor."); + exit(1); + } + /* Get photo URL and ID */ + $candidate['image_url'] = $media['url']; + $candidate['image_id'] = $media['id']; + } + $candidate_data[$candidate['Candidate Name']] = $candidate; + } + fclose($handle); + } else { + error_log('Error opening candidates file'); + exit(1); + } + + /* Override pledge columns if pledges.csv is present */ + $pledges_file = dirname($file)."/pledges.csv"; + if (!file_exists($pledges_file)) continue; + + if (($handle = fopen($pledges_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); + } + } + + return $candidate_data; +} diff --git a/pledge-update/pledge-page.php b/pledge-update/pledge-page.php new file mode 100644 index 0000000..8128968 --- /dev/null +++ b/pledge-update/pledge-page.php @@ -0,0 +1,44 @@ + Date: Tue, 17 Sep 2024 22:19:24 +1000 Subject: [PATCH 3/8] Plumb in Matt's PHP template. --- pledge-update/page_renderer.php | 28 +++++ pledge-update/pledge-page.php | 30 ++--- pledge-update/template.php | 198 ++++++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+), 21 deletions(-) create mode 100644 pledge-update/page_renderer.php create mode 100644 pledge-update/template.php diff --git a/pledge-update/page_renderer.php b/pledge-update/page_renderer.php new file mode 100644 index 0000000..773a33a --- /dev/null +++ b/pledge-update/page_renderer.php @@ -0,0 +1,28 @@ +renderPledgePage($councilData, $candidateData, $mediaData); +if ($pageContent === null) { + exit(2); +} + +echo $pageContent; exit(0); diff --git a/pledge-update/template.php b/pledge-update/template.php new file mode 100644 index 0000000..a0cea5c --- /dev/null +++ b/pledge-update/template.php @@ -0,0 +1,198 @@ +Streets People Love Pledge and Survey"; +if (isset($config["survey"])) { + $surveyLink = $config["survey"]; +} + +?> + + +

The Streets People Love campaign has created scorecards for candidates in the 2024 council elections. Scorecards have been generated based on a candidate's engagement with the Streets People Love campaign, their commitment to our pledge, their responses to a survey and input from campaign members located in the local government area in which they are running.

+ + + +

Can't see a candidate you know is running? Candidates who don't take our survey won't appear on this page. Feel free to send your local candidates the and let them know it's important to local residents that they do take part, so that we can vote for those who want to build the streets people love.

+ + + + +
" alt="" class="wp-image-" style="aspect-ratio:16/9;object-fit:cover"/>
+ + + + 1) { + $wardsDescription = $config['councilName'] . " is divided into " . $wardCount . " wards:"; + } else { + $wardsDescription = $config['councilName'] . " is unsubdivided and does not contain any wards."; + } + + ?> + + +

+ + + + +
" target="_blank" rel="noreferrer noopener">" alt="" class="wp-image-" style="width:550px"/>
+ + + + 1): ?> + + 8) { + $wardListChunkSize = ceil($wardCount / 2); + } else { + $wardListChunkSize = $wardCount; + } + + $wardChunks = array_chunk($config['wardNames'], $wardListChunkSize); + + ?> + +
+ + + +
+ + + +
    + + + +
  • + + + +
+ + + +
+ + + +
+ + + +

+ + + + + + $groupName): ?> + + +

+ + + 0): + ?> + + + + + +
+ + + +
+ + + + + +
+ + + +

+ + + +

+ + + +
+ + + +
+ + + + + + +

No candidates in this ward have completed the survey. Send your local candidates the and ask them to take part so that local residents can vote for the candidates who want to build the streets people love.

+ + + + + + + + +

+ + \ No newline at end of file From 82f65a2050097bf3640a5f03c9e83cc32cbeceba Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sat, 21 Sep 2024 16:53:24 +1000 Subject: [PATCH 4/8] Generate pledge council index. --- pledge-update/page_renderer.php | 2 +- pledge-update/pledge-page.php | 11 ++++++++- pledge-update/template.php | 41 ++++++++++++--------------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/pledge-update/page_renderer.php b/pledge-update/page_renderer.php index 773a33a..f7ce2dc 100644 --- a/pledge-update/page_renderer.php +++ b/pledge-update/page_renderer.php @@ -1,7 +1,7 @@ renderPledgePage($councilData, $candidateData, $mediaData); +$councils = []; +foreach ($pledgeCandidates as $key => $candidate) { + $councils[] = $candidate['Council']; +} +$councils = array_unique($councils); +asort($councils); + +//print_r($councils); + +$pageContent = $renderer->renderPledgePage($councils, $pledgeCandidates); if ($pageContent === null) { exit(2); diff --git a/pledge-update/template.php b/pledge-update/template.php index a0cea5c..fe326a3 100644 --- a/pledge-update/template.php +++ b/pledge-update/template.php @@ -5,9 +5,6 @@ function sluggify($input) { } $surveyLink = "Streets People Love Pledge and Survey"; -if (isset($config["survey"])) { - $surveyLink = $config["survey"]; -} ?> @@ -27,12 +24,10 @@ if (isset($config["survey"])) { 1) { - $wardsDescription = $config['councilName'] . " is divided into " . $wardCount . " wards:"; - } else { - $wardsDescription = $config['councilName'] . " is unsubdivided and does not contain any wards."; + if ($councilCount > 1) { + $wardsDescription = "Candidates from " . $councilCount . " wards have taken the pledge:"; } ?> @@ -41,39 +36,33 @@ if (isset($config["survey"])) {

- - -
" target="_blank" rel="noreferrer noopener">" alt="" class="wp-image-" style="width:550px"/>
- - - - 1): ?> + 1): ?> 8) { - $wardListChunkSize = ceil($wardCount / 2); + if ($councilCount > 8) { + $councilListChunkSize = ceil($councilCount / 2); } else { - $wardListChunkSize = $wardCount; + $councilListChunkSize = $councilCount; } - $wardChunks = array_chunk($config['wardNames'], $wardListChunkSize); + $councilChunks = array_chunk($councils, $councilListChunkSize); ?> - -
+ +
- +
    - + -
  • +
  • @@ -87,7 +76,7 @@ if (isset($config["survey"])) {
- +

@@ -195,4 +184,4 @@ if (isset($config["survey"])) {

- \ No newline at end of file + From cba26faf311f33388b994cf6a5fa4ab025d91691 Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sat, 21 Sep 2024 17:24:50 +1000 Subject: [PATCH 5/8] Show photographs. --- pledge-update/template.php | 53 +++++++++----------------------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/pledge-update/template.php b/pledge-update/template.php index fe326a3..047a745 100644 --- a/pledge-update/template.php +++ b/pledge-update/template.php @@ -76,38 +76,21 @@ $surveyLink = "Streets People Lo
- +

- - - $groupName): ?> + $council): ?> - -

+ +

0): @@ -116,10 +99,10 @@ $surveyLink = "Streets People Lo - + From bbffeb89f1a2c4fd09bfd940fa508089fd8fadd1 Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sat, 21 Sep 2024 17:36:04 +1000 Subject: [PATCH 6/8] Update text. --- pledge-update/template.php | 109 ++++++++++++++----------------------- 1 file changed, 42 insertions(+), 67 deletions(-) diff --git a/pledge-update/template.php b/pledge-update/template.php index 047a745..5c2637d 100644 --- a/pledge-update/template.php +++ b/pledge-update/template.php @@ -1,41 +1,25 @@ Streets People Love Pledge and Survey"; - ?> -

The Streets People Love campaign has created scorecards for candidates in the 2024 council elections. Scorecards have been generated based on a candidate's engagement with the Streets People Love campaign, their commitment to our pledge, their responses to a survey and input from campaign members located in the local government area in which they are running.

+

The Streets People Love campaign offers council candidates the opportunity to take the following pledge:

-

Can't see a candidate you know is running? Candidates who don't take our survey won't appear on this page. Feel free to send your local candidates the and let them know it's important to local residents that they do take part, so that we can vote for those who want to build the streets people love.

+

If elected Councillor, I pledge to allocate budget and street space to build streets people love, and ensure that residents of all ages and abilities can safely move around our council area, irrespective of whether they choose to walk, cycle, wheel, use public transport or drive.

- - -
" alt="" class="wp-image-" style="aspect-ratio:16/9;object-fit:cover"/>
- - - - 1) { - $wardsDescription = "Candidates from " . $councilCount . " wards have taken the pledge:"; - } - - ?> - - -

+ +

Candidates from these councils have taken the pledge:

+ + 1): ?> Streets People Lo return $candidate['Council'] === $council; }); - if (count($groupCandidates) > 0): ?> - + $chunkedCouncilCandidates = array_chunk($groupCandidates, $columnCount); + ?> - - -
- - - -
+ + +
+ + + +
- - + + ?> - -
- + +
+ - -

- + +

+ - + -
- - +
+ + -
- - +
+ + - - - -

No candidates in this ward have completed the survey. Send your local candidates the and ask them to take part so that local residents can vote for the candidates who want to build the streets people love.

- - - - From 5e8170ecef96a77fd12362426d2c8e7c48b7442b Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sat, 21 Sep 2024 17:44:38 +1000 Subject: [PATCH 7/8] Highlight pledge text. --- pledge-update/template.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pledge-update/template.php b/pledge-update/template.php index 5c2637d..50eb782 100644 --- a/pledge-update/template.php +++ b/pledge-update/template.php @@ -8,8 +8,8 @@ function sluggify($input) {

The Streets People Love campaign offers council candidates the opportunity to take the following pledge:

- -

If elected Councillor, I pledge to allocate budget and street space to build streets people love, and ensure that residents of all ages and abilities can safely move around our council area, irrespective of whether they choose to walk, cycle, wheel, use public transport or drive.

+ +

If elected Councillor, I pledge to allocate budget and street space to build streets people love, and ensure that residents of all ages and abilities can safely move around our council area, irrespective of whether they choose to walk, cycle, wheel, use public transport or drive.

From efecbe1d765fe63aeca381138459d4471044fd4b Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sun, 22 Sep 2024 17:08:35 +1000 Subject: [PATCH 8/8] Change pledge text background colour. --- pledge-update/template.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pledge-update/template.php b/pledge-update/template.php index 50eb782..0e32c93 100644 --- a/pledge-update/template.php +++ b/pledge-update/template.php @@ -8,8 +8,8 @@ function sluggify($input) {

The Streets People Love campaign offers council candidates the opportunity to take the following pledge:

- -

If elected Councillor, I pledge to allocate budget and street space to build streets people love, and ensure that residents of all ages and abilities can safely move around our council area, irrespective of whether they choose to walk, cycle, wheel, use public transport or drive.

+ +

If elected Councillor, I pledge to allocate budget and street space to build streets people love, and ensure that residents of all ages and abilities can safely move around our council area, irrespective of whether they choose to walk, cycle, wheel, use public transport or drive.