From 71fbd4ad9bcd4f2bdb65b54302c52424b0d30309 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 30 Nov 2022 17:01:57 +0100 Subject: [PATCH] Add update function for POTA references --- application/controllers/Update.php | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/application/controllers/Update.php b/application/controllers/Update.php index 0133ba4c1..243ff1043 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -417,6 +417,43 @@ class Update extends CI_Controller { } } + public function update_pota() { + $csvfile = 'https://pota.app/all_parks.csv'; + + $potafile = './assets/json/pota.txt'; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $csvfile); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_USERAGENT, 'Cloudlog Updater'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $csv = curl_exec($ch); + curl_close($ch); + + $potafilehandle = fopen($potafile, 'w'); + $data = str_getcsv($csv,"\n"); + foreach ($data as $idx => $row) { + if ($idx == 0) continue; // Skip line we are not interested in + $row = str_getcsv($row, ','); + if ($row[0]) { + fwrite($potafilehandle, $row[0].PHP_EOL); + } + } + + fclose($potafilehandle); + if (file_exists($potafile)) + { + $nCount = count(file($potafile)); + if ($nCount > 0) + { + echo "DONE: " . number_format($nCount) . " POTA's saved"; + } else { + echo"FAILED: Empty file"; + } + } else { + echo"FAILED: Could not create pota.txt file locally"; + } + } } ?>