Skip to content

Commit 5203986

Browse files
committed
repeaterbook: use a distict user agent
Also display the errors on console when the JSON cannot be decoded.
1 parent 9dae87f commit 5203986

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/dzcb/repeaterbook.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
REPEATERBOOK_DEFAULT_STATES = ("Washington", "Oregon")
3030
REPEATERBOOK_CACHE_MAX_AGE = 3600 * 12.1 # 12 hours (and some change)
3131
REPEATERBOOK_DEFAULT_NAME_FORMAT = "{Callsign} {Nearest City} {Landmark}"
32+
REPEATERBOOK_USER_AGENT = "(dzcb, https://github.com/mycodeplug/dzcb, [email protected])"
3233
CSV_ZONE_NAME = "Zone Name"
3334
CSV_LAT = "Lat"
3435
CSV_LONG = "Long"
@@ -49,7 +50,7 @@ def cached_json(url, max_age=REPEATERBOOK_CACHE_MAX_AGE):
4950
global_last_fetched = time.time() - REPEATERBOOK_LAST_FETCH
5051
if global_last_fetched < REPEATERBOOK_API_DELAY:
5152
time.sleep(REPEATERBOOK_API_DELAY - global_last_fetched)
52-
resp = requests.get(url)
53+
resp = requests.get(url, headers={'User-Agent': REPEATERBOOK_USER_AGENT})
5354
REPEATERBOOK_LAST_FETCH = time.time()
5455
filepath.write_bytes(resp.content)
5556
return filepath
@@ -67,7 +68,12 @@ def iter_cached_repeaters(states=None, max_age=REPEATERBOOK_CACHE_MAX_AGE):
6768
)
6869
cached_json_file = cached_json(url, max_age=max_age)
6970
with open(cached_json_file, "r") as f:
70-
rb_api_resp = json.load(f)
71+
try:
72+
rb_api_resp = json.load(f)
73+
except Exception:
74+
f.seek(0)
75+
print(f.read())
76+
raise
7177
logger.info(
7278
"Load cached Repeaterbook data for %s: %s records (%s)",
7379
state,

0 commit comments

Comments
 (0)