Skip to content

Commit

Permalink
Fred/qrz (#3)
Browse files Browse the repository at this point in the history
* Use QRZ to find the email addres if it is not provided in tha ADIF file
* Add qrzlib dependency into workflow
  • Loading branch information
0x9900 authored Feb 16, 2024
1 parent 8bafe88 commit 6a6d0c1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pylint isort flake8
pip install adif_io PyYAML Pillow watchfiles
pip install adif_io PyYAML Pillow watchfiles qrzlib
- name: Lint check
continue-on-error: false
run: |
Expand Down
6 changes: 6 additions & 0 deletions eqsl.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ ituzone: 6
cqzone: 3
adif_file: /tmp/export.adif

# Some logging software do not export the email address in the ADIF file.
# eqsl will try to fetch the email address from qrz.com. For that to work
# you need to provide a qrz API key.
# The key can be found on qrz -> logbook -> settings -> API key
qrzr_key: 123-abc-456-def

smtp_server: <smtp_server>
smtp_login: <smtp_login>
smtp_password: <smtp_password>
Expand Down
20 changes: 19 additions & 1 deletion eqsl/_eqsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from tempfile import NamedTemporaryFile

import adif_io
import qrzlib
import yaml
from PIL import Image, ImageDraw, ImageFont

Expand Down Expand Up @@ -94,11 +95,28 @@ def __init__(self, qso, cfg):
self.tx_pwr = int(qso.get('TX_PWR', 100))
self.timestamp = qso_timestamp(date_on, time_on)
self.name = qso.get('NAME', 'Dear OM')
self.email = qso['EMAIL']
self.email = qso.get('EMAIL', self.email_lookup(self.call, cfg))
self.pota_ref = qso.get('POTA_REF')
self.sota_ref = qso.get('SOTA_REF')
self.lang = qso.get('COUNTRY', 'default').lower()

def email_lookup(self, call, cfg):
logging.warning('Email address for %s not found in the ADIF file, using qrz.com', call)
try:
key = config.qrz_key
except AttributeError:
logging.error('Impossible to retrieve the email from qrz.com: API key missing')
raise SystemExit('qrz.com API key missing') from None

qrz = qrzlib.QRZ()
qrz.authenticate(cfg.call, key)
try:
qrz.get_call(call)
return qrz.email
except qrzlib.QRZ.NotFound:
logging.error('No email address found for %s', call)
return None


def draw_rectangle(draw, coord, color=(0x44, 0x79, 0x9), width=1, fill=(0x75, 0xDB, 0xCD, 190)):
draw.rectangle(coord, outline=color, fill=fill)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"PyYAML",
"adif_io",
"watchfiles",
"qrzlib",
]

[tool.setuptools]
Expand Down

0 comments on commit 6a6d0c1

Please sign in to comment.