Collect data for pledge rotation.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.swp
|
||||
50
pledge-update/main.php
Normal file
50
pledge-update/main.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
$options = getopt("", ["candidates-files:"]);
|
||||
|
||||
if (isset($options['candidates-files'])) {
|
||||
$candidatesFiles = $options['candidates-files'];
|
||||
} else {
|
||||
error_log("Error: Missing required option '--candidates-files'.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$files = explode(" ", $candidatesFiles);
|
||||
|
||||
$candidateData = [];
|
||||
foreach ($files as $key => $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);
|
||||
16
update-pledges.sh
Normal file → Executable file
16
update-pledges.sh
Normal file → Executable file
@@ -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[*]}"
|
||||
|
||||
Reference in New Issue
Block a user