mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 16:59:25 +00:00
Disk cache for QRZ lookup data #9
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
/.venv
|
/.venv
|
||||||
__pycache__
|
__pycache__
|
||||||
*.pyc
|
*.pyc
|
||||||
|
/.qrz_callsign_lookup_cache
|
||||||
/sota_summit_data_cache.sqlite
|
/sota_summit_data_cache.sqlite
|
||||||
/gma_ref_info_cache.sqlite
|
/gma_ref_info_cache.sqlite
|
||||||
/config.yml
|
/config.yml
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from diskcache import Cache
|
||||||
from pyhamtools import LookupLib, Callinfo
|
from pyhamtools import LookupLib, Callinfo
|
||||||
from pyhamtools.locator import latlong_to_locator
|
from pyhamtools.locator import latlong_to_locator
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ QRZ_AVAILABLE = config["qrz-password"] != ""
|
|||||||
if QRZ_AVAILABLE:
|
if QRZ_AVAILABLE:
|
||||||
LOOKUP_LIB_QRZ = LookupLib(lookuptype="qrz", username=config["qrz-username"], pwd=config["qrz-password"])
|
LOOKUP_LIB_QRZ = LookupLib(lookuptype="qrz", username=config["qrz-username"], pwd=config["qrz-password"])
|
||||||
# Cache of QRZ.com callsign lookups, so we don't repeatedly call the API for stuff we already know
|
# Cache of QRZ.com callsign lookups, so we don't repeatedly call the API for stuff we already know
|
||||||
QRZ_CALLSIGN_DATA_CACHE = {}
|
QRZ_CALLSIGN_DATA_CACHE = Cache('.qrz_callsign_lookup_cache')
|
||||||
|
|
||||||
# Infer a mode from the comment
|
# Infer a mode from the comment
|
||||||
def infer_mode_from_comment(comment):
|
def infer_mode_from_comment(comment):
|
||||||
@@ -81,12 +82,13 @@ def infer_itu_zone_from_callsign(call):
|
|||||||
# Utility method to get QRZ.com data from cache if possible, if not get it from the API and cache it
|
# Utility method to get QRZ.com data from cache if possible, if not get it from the API and cache it
|
||||||
def get_qrz_data_for_callsign(call):
|
def get_qrz_data_for_callsign(call):
|
||||||
# Fetch from cache if we can, otherwise fetch from the API and cache it
|
# Fetch from cache if we can, otherwise fetch from the API and cache it
|
||||||
if call in QRZ_CALLSIGN_DATA_CACHE:
|
qrz_data = QRZ_CALLSIGN_DATA_CACHE.get(call)
|
||||||
return QRZ_CALLSIGN_DATA_CACHE[call]
|
if qrz_data:
|
||||||
|
return qrz_data
|
||||||
elif QRZ_AVAILABLE:
|
elif QRZ_AVAILABLE:
|
||||||
try:
|
try:
|
||||||
data = LOOKUP_LIB_QRZ.lookup_callsign(callsign=call)
|
data = LOOKUP_LIB_QRZ.lookup_callsign(callsign=call)
|
||||||
QRZ_CALLSIGN_DATA_CACHE[call] = data
|
QRZ_CALLSIGN_DATA_CACHE.add(call, data, expire=604800) # 1 week in seconds
|
||||||
return data
|
return data
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# QRZ had no info for the call, that's OK
|
# QRZ had no info for the call, that's OK
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ telnetlib3~=2.0.8
|
|||||||
pytz~=2025.2
|
pytz~=2025.2
|
||||||
requests~=2.32.5
|
requests~=2.32.5
|
||||||
aprslib~=0.7.2
|
aprslib~=0.7.2
|
||||||
|
diskcache~=5.6.3
|
||||||
Reference in New Issue
Block a user