From c6ff0e24b12416ff35f025f3e4893cf6380d9953 Mon Sep 17 00:00:00 2001 From: Matt Way Date: Thu, 15 Aug 2024 15:00:52 +1000 Subject: [PATCH] WIP create csv-normaliser --- .../.devcontainer/devcontainer.json | 30 ++++++++ csv-normaliser/.vscode/launch.json | 14 ++++ csv-normaliser/main.php | 69 +++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 csv-normaliser/.devcontainer/devcontainer.json create mode 100644 csv-normaliser/.vscode/launch.json create mode 100644 csv-normaliser/main.php diff --git a/csv-normaliser/.devcontainer/devcontainer.json b/csv-normaliser/.devcontainer/devcontainer.json new file mode 100644 index 0000000..40ade77 --- /dev/null +++ b/csv-normaliser/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/php +{ + "name": "PHP", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/php:1-8.3", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Configure tool-specific properties. + // "customizations": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [8000], + + // Use 'portsAttributes' to set default properties for specific forwarded ports. More info: https://code.visualstudio.com/docs/remote/devcontainerjson-reference. + "portsAttributes": { + "8000": { + "label": "Hello Remote World", + "onAutoForward": "notify" + } + } + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html" + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/csv-normaliser/.vscode/launch.json b/csv-normaliser/.vscode/launch.json new file mode 100644 index 0000000..f57f2b9 --- /dev/null +++ b/csv-normaliser/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch application", + "type": "php", + "request": "launch", + "program": "${workspaceFolder}/main.php", + "args": [], + "cwd": "${workspaceFolder}", + "port": 9000 + } + ] +} \ No newline at end of file diff --git a/csv-normaliser/main.php b/csv-normaliser/main.php new file mode 100644 index 0000000..39cec97 --- /dev/null +++ b/csv-normaliser/main.php @@ -0,0 +1,69 @@ + $value) { + $candidate[$value] = $data[$key]; + } + $candidateData[] = $candidate; + } + fclose($handle); +} else { + error_log('Error opening candidates file'); + exit(1); +} + +$candidateData = array_filter($candidateData, function ($candidate) use ($councilData) { + return isset($candidate["Council"]) && $candidate["Council"] === $councilData['shortName']; +}); + +if (empty($candidateData)) { + error_log("Failed to load any candidates for " . $councilData['shortName']); +} + +if (isset($options['media-file'])) { + $mediaFileContents = file_get_contents($options['media-file']); +} else { + error_log("Error: Missing required option '--media-file'."); + exit(1); +} + +$mediaData = json_decode($mediaFileContents, true); + +$renderer = new SPLPageRenderer(); +$pageContent = $renderer->renderCouncilPage($councilData, $candidateData, $mediaData); +if ($pageContent === null) { + exit(2); +} + +echo $pageContent; +exit(0);