Skip to content

Commit

Permalink
repeaterbook: use a distict user agent
Browse files Browse the repository at this point in the history
Also display the errors on console when the JSON cannot be decoded.
  • Loading branch information
masenf committed Jan 21, 2024
1 parent 9dae87f commit 5203986
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dzcb/repeaterbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
REPEATERBOOK_DEFAULT_STATES = ("Washington", "Oregon")
REPEATERBOOK_CACHE_MAX_AGE = 3600 * 12.1 # 12 hours (and some change)
REPEATERBOOK_DEFAULT_NAME_FORMAT = "{Callsign} {Nearest City} {Landmark}"
REPEATERBOOK_USER_AGENT = "(dzcb, https://github.com/mycodeplug/dzcb, kf7hvm@0x26.net)"
CSV_ZONE_NAME = "Zone Name"
CSV_LAT = "Lat"
CSV_LONG = "Long"
Expand All @@ -49,7 +50,7 @@ def cached_json(url, max_age=REPEATERBOOK_CACHE_MAX_AGE):
global_last_fetched = time.time() - REPEATERBOOK_LAST_FETCH
if global_last_fetched < REPEATERBOOK_API_DELAY:
time.sleep(REPEATERBOOK_API_DELAY - global_last_fetched)
resp = requests.get(url)
resp = requests.get(url, headers={'User-Agent': REPEATERBOOK_USER_AGENT})
REPEATERBOOK_LAST_FETCH = time.time()
filepath.write_bytes(resp.content)
return filepath
Expand All @@ -67,7 +68,12 @@ def iter_cached_repeaters(states=None, max_age=REPEATERBOOK_CACHE_MAX_AGE):
)
cached_json_file = cached_json(url, max_age=max_age)
with open(cached_json_file, "r") as f:
rb_api_resp = json.load(f)
try:
rb_api_resp = json.load(f)
except Exception:
f.seek(0)
print(f.read())
raise
logger.info(
"Load cached Repeaterbook data for %s: %s records (%s)",
state,
Expand Down

0 comments on commit 5203986

Please # to comment.