Skip to content

Commit

Permalink
Fix a problem with the cache
Browse files Browse the repository at this point in the history
Fix problem where a request was sent to qrz.com even when the email was provides
  • Loading branch information
0x9900 committed Feb 17, 2024
1 parent 66d0c56 commit 56a0702
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions eqsl/_eqsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import dbm
import logging
import marshal
import os
import pickle
import smtplib
import ssl
import string
Expand Down Expand Up @@ -95,7 +95,9 @@ 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.get('EMAIL', self.email_lookup(self.call, cfg))
self.email = qso.get('EMAIL')
if not self.email:
self.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()
Expand Down Expand Up @@ -308,8 +310,8 @@ def already_sent(qso):
key = f'{qso.call}-{qso.band}-{qso.mode}'.upper()
try:
with dbm.open(config.qsl_cache, 'r') as qdb:
cached = pickle.loads(qdb[key])
if cached.timestamp > datetime.utcnow().timestamp() - CACHE_EXPIRE:
cached = marshal.loads(qdb[key])
if cached['_cache_time'] > datetime.utcnow().timestamp() - CACHE_EXPIRE:
return True
except dbm.error:
pass
Expand All @@ -318,7 +320,9 @@ def already_sent(qso):

try:
with dbm.open(config.qsl_cache, 'c') as qdb:
qdb[key] = pickle.dumps(qso)
cache = asdict(qso)
cache['_cache_time'] = datetime.utcnow().timestamp()
qdb[key] = marshal.dumps(cache)
except IOError as err:
logging.warning(err)
return False
Expand Down

0 comments on commit 56a0702

Please sign in to comment.