diff --git a/locationdata.py b/locationdata.py index 3b521f2..ed9df2e 100644 --- a/locationdata.py +++ b/locationdata.py @@ -6,6 +6,8 @@ import maidenhead as mh # pip install maidenhead import requests # pip install requests import bs4 as bs # pip install beautifulsoup4 +URL_TIMEOUT = 10 # wait time for URL requests + def where_am_i(lat=0, lon=0): whereIam = "" if float(lat) == 0 and float(lon) == 0: @@ -27,7 +29,7 @@ def get_tide(lat=0, lon=0): if float(lat) == 0 and float(lon) == 0: return "no location data: does your device have GPS?" station_lookup_url = "https://api.tidesandcurrents.noaa.gov/mdapi/prod/webapi/tidepredstations.json?lat=" + str(lat) + "&lon=" + str(lon) + "&radius=50" - station_data = requests.get(station_lookup_url, timeout=10) + station_data = requests.get(station_lookup_url, timeout=URL_TIMEOUT) if(station_data.ok): station_json = station_data.json() #get first station id in 50 mile radius @@ -35,8 +37,8 @@ def get_tide(lat=0, lon=0): else: return "error fetching station data" - station_url="https://tidesandcurrents.noaa.gov/noaatidepredictions.html?id="+station_id - station_data = requests.get(station_url, timeout=10) + station_url = "https://tidesandcurrents.noaa.gov/noaatidepredictions.html?id=" + station_id + station_data = requests.get(station_url, URL_TIMEOUT=10) if(station_data.ok): #extract table class="table table-condensed" soup = bs.BeautifulSoup(station_data.text, 'html.parser') @@ -68,7 +70,7 @@ def get_weather(lat=0, lon=0): if float(lat) == 0 and float(lon) == 0: return "no location data: does your device have GPS?" weather_url = "https://forecast.weather.gov/MapClick.php?FcstType=text&lat=" + str(lat) + "&lon=" + str(lon) - weather_data = requests.get(weather_url, timeout=10) + weather_data = requests.get(weather_url, URL_TIMEOUT=10) if(weather_data.ok): soup = bs.BeautifulSoup(weather_data.text, 'html.parser') table = soup.find('div', id="detailed-forecast-body") diff --git a/mesh-bot.py b/mesh-bot.py index 8ba92fa..9c0e85f 100755 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -34,7 +34,7 @@ except Exception as e: print(f"System: Critical Error script abort. {e}") exit() -def auto_response(message,snr,rssi,hop,message_from_id): +def auto_response(message, snr, rssi, hop, message_from_id): #Auto response to messages if "ping" in message.lower(): #Check if the user added @foo to the message @@ -256,7 +256,7 @@ def get_node_location(number): print (f"{log_timestamp()} System: No nodes found") return position -def send_message(message,ch,nodeid): +def send_message(message, ch, nodeid): #if message over 160 characters, split it into multiple messages if len(message) > 160: #message_list = [message[i:i+160] for i in range(0, len(message), 160)] diff --git a/pong-bot.py b/pong-bot.py index d4c1faa..4dbc672 100755 --- a/pong-bot.py +++ b/pong-bot.py @@ -28,7 +28,7 @@ except Exception as e: print(f"System: Critical Error script abort. {e}") exit() -def auto_response(message,snr,rssi,hop): +def auto_response(message, snr, rssi, hop): #Auto response to messages if "ping" in message.lower(): #Check if the user added @foo to the message @@ -195,7 +195,7 @@ def get_node_list(): node_list.append("Nothing heard") return node_list -def send_message(message,ch,nodeid): +def send_message(message, ch, nodeid): if nodeid == 0: #Send to channel interface.sendText(text=message,channelIndex=ch) diff --git a/solarconditions.py b/solarconditions.py index 0cb53ac..a521f30 100644 --- a/solarconditions.py +++ b/solarconditions.py @@ -8,12 +8,15 @@ from datetime import datetime import ephem # pip install pyephem from datetime import timedelta +# default location for solar conditions if none is provided LATITUDE = 48.50 LONGITUDE = -123.0 +URL_TIMEOUT = 10 # wait time for URL requests + def hf_band_conditions(): hf_cond = "" - band_cond = requests.get("https://www.hamqsl.com/solarxml.php", timeout=5) + band_cond = requests.get("https://www.hamqsl.com/solarxml.php", timeout=URL_TIMEOUT) if(band_cond.ok): solarxml = xml.dom.minidom.parseString(band_cond.text) for i in solarxml.getElementsByTagName("band"): @@ -26,7 +29,7 @@ def hf_band_conditions(): def solar_conditions(): solar_cond = "" # get the solar conditions from the xml at "https://www.hamqsl.com/solarxml.php" - solar_cond = requests.get("https://www.hamqsl.com/solarxml.php", timeout=5) + solar_cond = requests.get("https://www.hamqsl.com/solarxml.php", timeout=URL_TIMEOUT) if(solar_cond.ok): solar_xml = xml.dom.minidom.parseString(solar_cond.text) for i in solar_xml.getElementsByTagName("solardata"): @@ -43,7 +46,7 @@ def solar_conditions(): def drap_xray_conditions(): drap_cond = "" - drap_cond = requests.get("https://services.swpc.noaa.gov/text/drap_global_frequencies.txt", timeout=5) + drap_cond = requests.get("https://services.swpc.noaa.gov/text/drap_global_frequencies.txt", timeout=URL_TIMEOUT) if(drap_cond.ok): drap_list = drap_cond.text.split('\n') x_filter = '# X-RAY Message :'