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[*]}"