From f9c151bfaef95ff4ce19d4054bdd9105d00d71bd Mon Sep 17 00:00:00 2001 From: Kim Taylor Date: Sun, 22 Sep 2024 22:57:35 +1000 Subject: [PATCH] Start generating image download script. --- csv-generic/csv-to-json.php | 20 ------------ csv-generic/gen-generic.php | 45 +++----------------------- csv-generic/gen-image-map.php | 54 +++++++++++++++++++++++++++++++ csv-generic/parse_generic_csv.php | 42 ++++++++++++++++++++++++ get-generic.sh | 13 ++++++-- 5 files changed, 111 insertions(+), 63 deletions(-) delete mode 100644 csv-generic/csv-to-json.php create mode 100644 csv-generic/gen-image-map.php diff --git a/csv-generic/csv-to-json.php b/csv-generic/csv-to-json.php deleted file mode 100644 index 9bef38b..0000000 --- a/csv-generic/csv-to-json.php +++ /dev/null @@ -1,20 +0,0 @@ - 70) $score_sum += $score; - else $score_sum -= 10; - } - } - - if ($score_sum > $max_score) { - $max_score = $score_sum; - $match_lga = $lga; - } - } - - $max_score = 0; - foreach ($match_lga['wardNames'] as $ward) { - similar_text($ward, $candidate['Ward'], $score); - if ($score > $max_score) { - $max_score = $score; - $match_ward = $ward; - } - } - - $candidate['match_lga'] = $match_lga['slug']; - $candidate['match_ward'] = $match_ward; -} - -/* Get picture */ -foreach ($candidate_data as &$candidate) { - $candidate['match_picture'] = ""; -} - $header = ["Ward", "Candidate Name", "Rating", "Picture"]; /* Generate candidates-generic.csv */ @@ -115,7 +78,7 @@ foreach ($lga_list as $lga) { $candidate['match_ward'], $candidate['Name'], $candidate['Score'], - $candidate['match_picture'], + $candidate['Photo'], ]; if (fputcsv($handle, $fields) === FALSE) { diff --git a/csv-generic/gen-image-map.php b/csv-generic/gen-image-map.php new file mode 100644 index 0000000..3c94c1b --- /dev/null +++ b/csv-generic/gen-image-map.php @@ -0,0 +1,54 @@ + 70) $score_sum += $score; + else $score_sum -= 10; + } + } + + if ($score_sum > $max_score) { + $max_score = $score_sum; + $match_lga = $lga; + } + } + + $max_score = 0; + foreach ($match_lga['wardNames'] as $ward) { + similar_text($ward, $candidate['Ward'], $score); + if ($score > $max_score) { + $max_score = $score; + $match_ward = $ward; + } + } + + $candidate['match_lga'] = $match_lga['slug']; + $candidate['match_ward'] = $match_ward; + } +} diff --git a/get-generic.sh b/get-generic.sh index dd1060a..28ef8ed 100755 --- a/get-generic.sh +++ b/get-generic.sh @@ -15,6 +15,15 @@ for folder in "$DATA_PATH"/*; do fi done -#php csv-generic/csv-to-json.php --generic-csv $DATA_LOC/responses.csv -php csv-generic/gen-generic.php --generic-csv $GENERIC_SURVEY --config-files "${config_files[*]}" +image_map=$(php csv-generic/gen-image-map.php --generic-csv $GENERIC_SURVEY --config-files "${config_files[*]}") + +for key in $(jq -r 'keys[]' <<< $image_map) ; do + url=$(jq -r ".[\"$key\"][\"url\"]" <<< $image_map) + lga=$(jq -r ".[\"$key\"][\"match_lga\"]" <<< $image_map) + dst=$DATA_PATH/$lga/$key + echo wget $url -O $dst + break +done + +#php csv-generic/gen-generic.php --generic-csv $GENERIC_SURVEY --config-files "${config_files[*]}"