From 22d8b889fe1e35ff047d1b8944f5336ab43d2abe Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 6 Oct 2024 22:24:31 -0700 Subject: [PATCH] repeaterList enhancment --- config.template | 2 ++ mesh_bot.py | 8 +++++++- modules/locationdata.py | 39 +++++++++++++++++++++++++++++++++++++++ modules/settings.py | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/config.template b/config.template index 1a2a432..591dda1 100644 --- a/config.template +++ b/config.template @@ -104,6 +104,8 @@ NOAAalertCount = 2 UseMeteoWxAPI = False # Default to metric units rather than imperial useMetric = False +# repeaterList lookup location (rbook / artsci) +repeaterLookup = rbook # repeater module [repeater] diff --git a/mesh_bot.py b/mesh_bot.py index f73a658..c981690 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -727,7 +727,13 @@ def handle_whereami(message_from_id, deviceID, channel_number): def handle_repeaterQuery(message_from_id, deviceID, channel_number): location = get_node_location(message_from_id, deviceID, channel_number) - return getArtSciRepeaters(str(location[0]), str(location[1])) + if repeater_lookup == "rbook": + return getRepeaterBook(str(location[0]), str(location[1])) + elif repeaterLookup == "artsci": + return getArtSciRepeaters(str(location[0]), str(location[1])) + else: + return "Repeater lookup not enabled" + def handle_tide(message_from_id, deviceID, channel_number): location = get_node_location(message_from_id, deviceID, channel_number) diff --git a/modules/locationdata.py b/modules/locationdata.py index f4f2d1c..19455a6 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -68,6 +68,45 @@ def where_am_i(lat=0, lon=0, short=False, zip=False): logger.debug("Location:Error fetching location data with whereami, likely network error") return ERROR_FETCHING_DATA +def getRepeaterBook(lat=0, lon=0): + grid = mh.to_maiden(float(lat), float(lon)) + data = [] + repeater_url = f"https://www.repeaterbook.com/repeaters/prox_result.php?city={grid}&lat=&long=&distance=50&Dunit=m&band%5B%5D=4&band%5B%5D=16&freq=&call=&mode%5B%5D=1&mode%5B%5D=2&mode%5B%5D=4&mode%5B%5D=64&status_id=1&use=%25&use=OPEN&order=distance_calc%2C+state_id+ASC" + try: + msg = '' + response = requests.get(repeater_url) + soup = BeautifulSoup(response.text, 'html.parser') + table = soup.find('table', attrs={'class': 'w3-table w3-striped w3-responsive w3-mobile w3-auto sortable'}) + if table is not None: + cells = table.find_all('td') + data = [] + for i in range(0, len(cells), 11): + if i + 10 < len(cells): #avoid IndexError + repeater = { + 'frequency': cells[i].text.strip() if i < len(cells) else 'N/A', + 'offset': cells[i + 1].text.strip() if i + 1 < len(cells) else 'N/A', + 'tone': cells[i + 2].text.strip() if i + 2 < len(cells) else 'N/A', + 'call_sign': cells[i + 3].text.strip() if i + 3 < len(cells) else 'N/A', + 'location': cells[i + 4].text.strip() if i + 4 < len(cells) else 'N/A', + 'state': cells[i + 5].text.strip() if i + 5 < len(cells) else 'N/A', + 'use': cells[i + 6].text.strip() if i + 6 < len(cells) else 'N/A', + 'mode': cells[i + 7].text.strip() if i + 7 < len(cells) else 'N/A', + 'distance': cells[i + 8].text.strip() if i + 8 < len(cells) else 'N/A', + 'direction': cells[i + 9].text.strip() if i + 9 < len(cells) else 'N/A' + } + data.append(repeater) + else: + msg = "bug?Not enough columns" + else: + msg = "bug?Table not found" + except Exception as e: + msg = "No repeaters found 😔" + # Limit the output to the first 4 repeaters + for repeater in data[:4]: + msg += f"{repeater['call_sign']}📶{repeater['frequency']}{repeater['offset']},{repeater['tone']}🧭{repeater['direction']}" + if repeater != data[-1]: msg += '\n' + return msg + def getArtSciRepeaters(lat=0, lon=0): # UK api_url = "https://api-beta.rsgb.online/all/systems" #grid = mh.to_maiden(float(lat), float(lon)) diff --git a/modules/settings.py b/modules/settings.py index 33953a9..fc00b76 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -130,6 +130,7 @@ try: forecastDuration = config['location'].getint('NOAAforecastDuration', 4) # NOAA forcast days numWxAlerts = config['location'].getint('NOAAalertCount', 2) # default 2 alerts wxAlertsEnabled = config['location'].getboolean('NOAAalertsEnabled', True) # default True not enabled yet + repeater_lookup = config['location'].get('repeaterLookup', 'rbook') # default repeater lookup source # bbs bbs_enabled = config['bbs'].getboolean('enabled', False)