[LOTW] LoTW user lookup switched from importing CSV to database to PHP reading it directly reducing MySQL load

pull/627/head
Peter Goodhall 2020-09-21 14:02:50 +01:00
rodzic 2c44517370
commit d4a164fc94
4 zmienionych plików z 148412 dodań i 30 usunięć

Wyświetl plik

@ -67,11 +67,32 @@ class Logbook extends CI_Controller {
$this->load->model('user_model');
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
$this->load->model('lotw_user');
$lotw_member = $this->lotw_user->check($callsign);
// Check if callsign is an LOTW User
$lotw_member = "";
$lotw_file_name = "./updates/lotw_users.csv";
if (file_exists($lotw_file_name)) {
$f = fopen($lotw_file_name, "r");
$result = false;
while ($row = fgetcsv($f)) {
if ($row[0] == strtoupper($callsign)) {
$result = $row[0];
$lotw_member = "active";
break;
}
}
if($lotw_member != "active") {
$lotw_member = "not found";
}
fclose($f);
} else {
$lotw_member = "not found";
}
// Check Database for all other data
$this->load->model('logbook_model');
$return = [

Wyświetl plik

@ -819,42 +819,41 @@ class Lotw extends CI_Controller {
}
/*
Load the ARRL LOTW User Activity CSV into LOTW User Table for cross checking when logging
*/
function load_users() {
set_time_limit(0);
$this->load->model('lotw_user');
Load the ARRL LOTW User Activity CSV and saves into uploads/lotw_users.csv
*/
public function load_users() {
$contents = file_get_contents('https://lotw.arrl.org/lotw-user-activity.csv', true);
$this->lotw_user->empty_table();
if($contents === FALSE) {
echo "something went wrong";
} else {
$file = './updates/lotw_users.csv';
$row = 1;
if (($handle = fopen("https://lotw.arrl.org/lotw-user-activity.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
if(isset($data[2])) {
$callsign = $data[0];
$upload_date = $data[1]." ".$data[2];
$this->lotw_user->add_lotwuser($callsign, $upload_date);
}
}
fclose($handle);
}
if(!is_file($file)){ // Some simple example content.
file_put_contents($file, $contents); // Save our content to the file.
}
echo "LoTW User Data Saved.";
}
}
/*
Check if callsign is an active LOTW user and return whether its true or not
*/
function lotw_usercheck($callsign) {
$this->load->model('lotw_user');
$lotw_user_result = $this->lotw_user->check($callsign);
$f = fopen('./updates/lotw_users.csv', "r");
$result = false;
while ($row = fgetcsv($f)) {
if ($row[0] == strtoupper($callsign)) {
$result = $row[0];
echo "Found";
break;
} else {
echo "Not Found"
break;
}
}
fclose($f);
}
function signlog($sign_key, $string) {

Wyświetl plik

@ -256,5 +256,39 @@ class Update extends CI_Controller {
}
}
public function download_lotw_users() {
$contents = file_get_contents('https://lotw.arrl.org/lotw-user-activity.csv', true);
if($contents === FALSE) {
echo "something went wrong";
} else {
$file = './updates/lotw_users.csv';
if(!is_file($file)){ // Some simple example content.
file_put_contents($file, $contents); // Save our content to the file.
}
echo "LoTW User Data Saved.";
}
}
public function lotw_check() {
$f = fopen('./updates/lotw_users.csv', "r");
$result = false;
while ($row = fgetcsv($f)) {
if ($row[0] == '2M0SQL/MM') {
$result = $row[0];
echo "found";
break;
}
}
fclose($f);
}
}
?>

148328
updates/lotw_users.csv 100644

Plik diff jest za duży Load Diff