added de-duplication based on DX call and frequency

This commit is contained in:
Michael Clemens 2022-07-20 22:57:30 +02:00
parent e740d7b1cc
commit de0f482277
2 changed files with 12 additions and 3 deletions

View File

@ -8,6 +8,7 @@ worked/confirmed before. To achieve this, it
* determines the DX station's continent * determines the DX station's continent
* determines if the DX station uses LotW * determines if the DX station uses LotW
* determines if the DX station's country has been confirmed via LotW * determines if the DX station's country has been confirmed via LotW
* de-duplicates spots
* and finally - if it's a new DXCC - sends the information to your dapnet pager * and finally - if it's a new DXCC - sends the information to your dapnet pager
# Limitations # Limitations
@ -21,6 +22,7 @@ The following limitations are present:
DXPager needs Python 3 and the following libraries: DXPager needs Python 3 and the following libraries:
* cachetools
* requests * requests
Furthermore, you need an account at LotW and hampager.de Furthermore, you need an account at LotW and hampager.de

View File

@ -38,7 +38,9 @@ from telnetlib import Telnet
from pathlib import Path from pathlib import Path
import json import json
import requests import requests
import hashlib
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from cachetools import TTLCache
class DXPager(): class DXPager():
@ -49,6 +51,8 @@ class DXPager():
self.print_banner() self.print_banner()
self.cache = TTLCache(maxsize=100, ttl=3600)
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
self.home_dir = str(Path.home()) self.home_dir = str(Path.home())
self.config_dir = self.home_dir + "/.config/dxpager/" self.config_dir = self.home_dir + "/.config/dxpager/"
@ -253,7 +257,6 @@ class DXPager():
try: try:
# Extract all necessary fields from the line and store them # Extract all necessary fields from the line and store them
# into different variables. # into different variables.
#print(line)
call_de = re.search('D(X|x) de (.+?): ', line).group(2) call_de = re.search('D(X|x) de (.+?): ', line).group(2)
freq = re.search(': +(.+?) ', line).group(1) freq = re.search(': +(.+?) ', line).group(1)
call_dx = re.search(freq + ' +(.+?) ', line).group(1) call_dx = re.search(freq + ' +(.+?) ', line).group(1)
@ -288,14 +291,18 @@ class DXPager():
[self.config['dapnet']['dapnet_callsigns']], \ [self.config['dapnet']['dapnet_callsigns']], \
"transmitterGroupNames": [self.config['dapnet']['dapnet_txgroup']], \ "transmitterGroupNames": [self.config['dapnet']['dapnet_txgroup']], \
"emergency": False}) "emergency": False})
cf = call_dx+freq
hash_entry = hashlib.md5(cf.encode())
# If the DX station's entity hasn't been worked/confirmed via # If the DX station's entity hasn't been worked/confirmed via
# LotW yet, the message will be sent to the dapnet API # LotW yet, the message will be sent to the dapnet API
if self.check_lotw_confirmed and self.config['lotw']['user'] != "N0CALL" \ if hash_entry.hexdigest() not in self.cache.keys() and \
self.check_lotw_confirmed and self.config['lotw']['user'] != "N0CALL" \
and cty_details[2] not in self.confirmed_entities: and cty_details[2] not in self.confirmed_entities:
response = requests.post(self.config['dapnet']['dapnet_url'], \ response = requests.post(self.config['dapnet']['dapnet_url'], \
data=dapnet_json, auth=HTTPBasicAuth(\ data=dapnet_json, auth=HTTPBasicAuth(\
self.config['dapnet']['dapnet_user'],\ self.config['dapnet']['dapnet_user'],\
self.config['dapnet']['dapnet_pass'])) self.config['dapnet']['dapnet_pass']))
self.cache[hash_entry.hexdigest()] = cf
print("!!! Sent to DAPNET: {} Response: {}".format(msg, response)) print("!!! Sent to DAPNET: {} Response: {}".format(msg, response))
else: else:
print(" Not sent to DAPNET: {}".format(msg)) print(" Not sent to DAPNET: {}".format(msg))