Merge pull request #852 from AndreasK79/dok_sota_autoupdate

Added autoupdate for DOK and SOTA file used for autocompletion
pull/770/head
Peter Goodhall 2021-01-26 20:36:42 +00:00 zatwierdzone przez GitHub
commit 9dab00b979
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 69 dodań i 0 usunięć

Wyświetl plik

@ -289,6 +289,75 @@ class Update extends CI_Controller {
fclose($f);
}
/*
* Used for autoupdating the DOK file which is used in the QSO entry dialog for autocompletion.
*/
public function update_dok() {
$contents = file_get_contents('https://www.df2et.de/cqrlog/dok.txt', true);
if($contents === FALSE) {
echo "Something went wrong with fetching the DOK file.";
} else {
$file = './assets/json/dok.txt';
file_put_contents($file, $contents); // Save our content to the file.
if (file_exists($file))
{
$nCount = count(file($file));
if ($nCount > 0)
{
echo "DONE: " . number_format($nCount) . " DOK's saved";
} else {
echo"FAILED: Empty file";
}
} else {
echo"FAILED: Could not create dok.txt file locally";
}
}
}
/*
* Used for autoupdating the SOTA file which is used in the QSO entry dialog for autocompletion.
*/
public function update_sota() {
$csvfile = 'https://www.sotadata.org.uk/summitslist.csv';
$sotafile = './assets/json/sota.txt';
if($csvfile === FALSE) {
echo "Something went wrong with fetching the SOTA file";
} else {
$csvhandle = fopen($csvfile,"r");
$data = fgetcsv($csvhandle,1000,","); // Skip line we are not interested in
$data = fgetcsv($csvhandle,1000,","); // Skip line we are not interested in
$data = fgetcsv($csvhandle,1000,",");
$sotafilehandle = fopen($sotafile, 'w');
do {
if ($data[0]) {
fwrite($sotafilehandle, $data[0].PHP_EOL);
}
} while ($data = fgetcsv($csvhandle,1000,","));
fclose($csvhandle);
fclose($sotafilehandle);
if (file_exists($sotafile))
{
$nCount = count(file($sotafile));
if ($nCount > 0)
{
echo "DONE: " . number_format($nCount) . " SOTA's saved";
} else {
echo"FAILED: Empty file";
}
} else {
echo"FAILED: Could not create sota.txt file locally";
}
}
}
}
?>