[Callbook][Update] Check for and populate blank Gridsquares from either QRZ or HamQTH

Check for and populate blank Gridsquares from callbook whether that is QRZ or HamQTH.

This will update missing grids if both COL_GRIDSQUARE & COL_VUCC_GRIDS is empty within the database table.

You can run this function using index.php/update/check_missing_grid
这个提交包含在:
Peter Goodhall 2021-03-31 15:47:51 +01:00 提交者 GitHub
当前提交 f41e1fbcea
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 71 次插入0 次删除

查看文件

@ -225,6 +225,11 @@ class Update extends CI_Controller {
}
public function check_missing_grid($all = false){
$this->load->model('logbook_model');
$this->logbook_model->check_missing_grid_id($all);
}
public function update_clublog_scp() {
$strFile = "./updates/clublog_scp.txt";
$url = "https://cdn.clublog.org/clublog.scp.gz";

查看文件

@ -2171,6 +2171,72 @@ class Logbook_model extends CI_Model {
print("$count updated\n");
}
public function check_missing_grid_id($all){
// get all records with no COL_GRIDSQUARE
$this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF");
// check which to update - records with no Gridsquare or all records
$this->db->where("COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = ''");
$where = "(COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = '') AND (COL_VUCC_GRIDS is NULL or COL_VUCC_GRIDS = '')";
$this->db->where($where);
$r = $this->db->get($this->config->item('table_name'));
$count = 0;
$this->db->trans_start();
if ($r->num_rows() > 0){
foreach($r->result_array() as $row){
$callsign = $row['COL_CALL'];
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null)
{
// Lookup using QRZ
$this->load->library('qrz');
if(!$this->session->userdata('qrz_session_key')) {
$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
$this->session->set_userdata('qrz_session_key', $qrz_session_key);
}
$callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'));
}
if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null)
{
// Load the HamQTH library
$this->load->library('hamqth');
if(!$this->session->userdata('hamqth_session_key')) {
$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
$this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
}
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
// If HamQTH session has expired, start a new session and retry the search.
if($callbook['error'] == "Session does not exist or expired") {
$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
$this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
}
}
if (isset($callbook))
{
$return['callsign_qra'] = $callbook['gridsquare'];
}
if ($return['callsign_qra'] != ''){
$sql = sprintf("update %s set COL_GRIDSQUARE = '%s' where COL_PRIMARY_KEY=%d",
$this->config->item('table_name'), $return['callsign_qra'], $row['COL_PRIMARY_KEY']);
$this->db->query($sql);
printf("Updating %s to %s\n<br/>", $row['COL_PRIMARY_KEY'], $return['callsign_qra']);
$count++;
}
}
}
$this->db->trans_complete();
print("$count updated\n");
}
public function check_for_station_id() {
$this->db->where('station_id =', 'NULL');