Start generating image download script.
This commit is contained in:
54
csv-generic/gen-image-map.php
Normal file
54
csv-generic/gen-image-map.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
require_once("parse_generic_csv.php");
|
||||
|
||||
$options = getopt("", ["generic-csv:", "config-files:"]);
|
||||
|
||||
if (isset($options['generic-csv'])) {
|
||||
$generic_csv = $options['generic-csv'];
|
||||
} else {
|
||||
error_log("Error: Missing required option '--generic-csv'.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (isset($options['config-files'])) {
|
||||
$config_files = $options['config-files'];
|
||||
} else {
|
||||
error_log("Error: Missing required option '--config-files'.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$config_files = explode(" ", $config_files);
|
||||
$candidate_data = parse_generic_csv($generic_csv);
|
||||
|
||||
$lga_list = [];
|
||||
/* Generate dictionary of LGAs and Wards */
|
||||
foreach ($config_files as $config_file) {
|
||||
$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);
|
||||
}
|
||||
$config['config-file'] = $config_file;
|
||||
$lga_list[] = $config;
|
||||
}
|
||||
|
||||
/* Match user typed LGA/Ward to our database */
|
||||
match_lga($candidate_data, $lga_list);
|
||||
|
||||
$image_map = [];
|
||||
foreach ($candidate_data as $candidate) {
|
||||
if (strlen($candidate['photo_url'])) {
|
||||
$map['url'] = $candidate['photo_url'];
|
||||
$map['match_lga'] = $candidate['match_lga'];
|
||||
$image_map[$candidate['Photo']] = $map;
|
||||
}
|
||||
}
|
||||
|
||||
$json_data = json_encode($image_map);
|
||||
|
||||
print_r($json_data);
|
||||
|
||||
exit(0);
|
||||
Reference in New Issue
Block a user