diff --git a/bbstools.py b/bbstools.py index 4d15eba..bac7d4c 100644 --- a/bbstools.py +++ b/bbstools.py @@ -3,7 +3,7 @@ from dadjokes import Dadjoke # pip install dadjokes -#global message list, later we will use a database on disk +# global message list, later we will use a database on disk bbs_messages = [[1, "Welcome to meshBBS", "Welcome to the BBS, please post a message!"]] def tell_joke(): @@ -23,7 +23,7 @@ def bbs_list_messages(): # message[0] is the messageID, message[1] is the subject message_list += "Msg #" + str(message[0]) + " " + message[1] + "\n" - #last newline removed + # last newline removed message_list = message_list[:-1] return message_list @@ -31,7 +31,7 @@ def bbs_delete_message(messageID = 0): # delete a message from the bbsdb if messageID > 0: bbs_messages.pop(messageID - 1) - #reset the messageID + # reset the messageID for i in range(len(bbs_messages)): bbs_messages[i][0] = i + 1 diff --git a/locationdata.py b/locationdata.py index 5d40715..7919c71 100644 --- a/locationdata.py +++ b/locationdata.py @@ -33,7 +33,7 @@ def get_tide(lat=0, lon=0): 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 + # get first station id in 50 mile radius station_id = station_json['stationList'][0]['stationId'] else: return "error fetching station data" @@ -41,13 +41,13 @@ def get_tide(lat=0, lon=0): station_url = "https://tidesandcurrents.noaa.gov/noaatidepredictions.html?id=" + station_id station_data = requests.get(station_url, timeout=URL_TIMEOUT) if(station_data.ok): - #extract table class="table table-condensed" + # extract table class="table table-condensed" soup = bs.BeautifulSoup(station_data.text, 'html.parser') table = soup.find('table', class_='table table-condensed') - #extract rows + # extract rows rows = table.find_all('tr') - #extract data from rows + # extract data from rows tide_data = [] for row in rows: row_text = "" @@ -59,7 +59,7 @@ def get_tide(lat=0, lon=0): tide_string = "" for data in tide_data: tide_string += data + "\n" - #trim off last newline + # trim off last newline tide_string = tide_string[:-1] return tide_string @@ -79,12 +79,12 @@ def get_weather(lat=0, lon=0): if table is None: return "no weather data found on NOAA for your location" else: - #get rows + # get rows rows = table.find_all('div', class_="row") - #extract data from rows + # extract data from rows for row in rows: - #shrink the text + # shrink the text line = row.text.replace("Monday", "Mon ") \ .replace("Tuesday", "Tue ") \ .replace("Wednesday", "Wed ") \ @@ -114,10 +114,10 @@ def get_weather(lat=0, lon=0): .replace("precipitation", "precip") \ .replace("showers", "shwrs") \ .replace("thunderstorms", "t-storms") - #only grab a few days of weather + # only grab a few days of weather if len(weather.split("\n")) < DAYS_OF_WEATHER: weather += line + "\n" - #trim off last newline + # trim off last newline weather = weather[:-1] return weather diff --git a/mesh-bot.py b/mesh-bot.py index e8c31d2..2de83c9 100755 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -101,7 +101,7 @@ def auto_response(message, snr, rssi, hop, message_from_id): elif "bbslist" in message.lower(): bot_response = bbs_list_messages() elif "bbspost" in message.lower(): - #Check if the user added a subject to the message + # Check if the user added a subject to the message if "$" in message: subject = message.split("$")[1].split("#")[0] subject = subject.rstrip() @@ -115,14 +115,14 @@ def auto_response(message, snr, rssi, hop, message_from_id): else: bot_response = "Please add a subject to the message. ex: bbspost $subject #message" elif "bbsread" in message.lower(): - #Check if the user added a message number to the message + # Check if the user added a message number to the message if "#" in message: messageID = int(message.split("#")[1]) bot_response = bbs_read_message(messageID) else: bot_response = "Please add a message number ex: bbsread #14" elif "bbsdelete" in message.lower(): - #Check if the user added a message number to the message + # Check if the user added a message number to the message if "#" in message: messageID = int(message.split("#")[1]) bot_response = bbs_delete_message(messageID) @@ -194,7 +194,7 @@ def onReceive(packet, interface): # respond with a direct message send_message(auto_response(message_string,snr,rssi,hop,message_from_id),channel_number,message_from_id) else: - #respond with welcome message + # respond with welcome message print(f"{log_timestamp()} Ignoring DM: {message_string} From: {get_name_from_number(message_from_id)}") send_message(welcome_message,channel_number,message_from_id) else: @@ -215,7 +215,7 @@ def onReceive(packet, interface): print("END of packet \n") def messageTrap(msg): - #Check if the message contains a trap word + # Check if the message contains a trap word message_list=msg.split(" ") for m in message_list: for t in trap_list: @@ -247,7 +247,7 @@ def get_node_list(): short_node_list = [] if interface.nodes: for node in interface.nodes.values(): - #ignore own + # ignore own if node['num'] != myNodeNum: node_name = get_name_from_number(node['num']) snr = node.get('snr', 0) @@ -255,7 +255,7 @@ def get_node_list(): # issue where lastHeard is not always present last_heard = node.get('lastHeard', 0) - #make a list of nodes with last heard time and SNR + # make a list of nodes with last heard time and SNR item = (node_name, last_heard, snr) node_list.append(item) @@ -272,7 +272,7 @@ def get_node_list(): return "Error Processing Node List" def get_node_location(number): - #Get the location of a node by its number from nodeDB on device + # Get the location of a node by its number from nodeDB on device latitude = 0 longitude = 0 position = [0,0] @@ -293,7 +293,7 @@ def get_node_location(number): return position def send_message(message, ch, nodeid): - #if message over 160 characters, split it into multiple messages + # 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)] # smarter word split @@ -307,7 +307,7 @@ def send_message(message, ch, nodeid): else: message_list.append(line) line = word + ' ' - message_list.append(line) #needed add contents of the last 'line' into the list + message_list.append(line) # needed add contents of the last 'line' into the list for m in message_list: if nodeid == 0: @@ -315,16 +315,16 @@ def send_message(message, ch, nodeid): print (f"{log_timestamp()} System: Sending Multi-Chunk: {m} To: Channel:{ch}") interface.sendText(text=m, channelIndex=ch) else: - #Send to DM + # Send to DM print (f"{log_timestamp()} System: Sending Multi-Chunk: {m} To: {get_name_from_number(nodeid)}") interface.sendText(text=m,channelIndex=ch, destinationId=nodeid) - else: #message is less than 160 characters + else: # message is less than 160 characters if nodeid == 0: - #Send to channel + # Send to channel print (f"{log_timestamp()} System: Sending: {message} To: Channel:{ch}") interface.sendText(text=message, channelIndex=ch) else: - #Send to DM + # Send to DM print (f"{log_timestamp()} System: Sending: {message} To: {get_name_from_number(nodeid)}") interface.sendText(text=message, channelIndex=ch, destinationId=nodeid) diff --git a/pong-bot.py b/pong-bot.py index fc0fb82..cdacdc3 100755 --- a/pong-bot.py +++ b/pong-bot.py @@ -29,9 +29,9 @@ except Exception as e: exit() def auto_response(message, snr, rssi, hop): - #Auto response to messages + # Auto response to messages if "ping" in message.lower(): - #Check if the user added @foo to the message + # Check if the user added @foo to the message if "@" in message: if hop == "Direct": bot_response = "PONG, " + f"SNR:{snr} RSSI:{rssi}" + " and copy: " + message.split("@")[1] @@ -52,7 +52,7 @@ def auto_response(message, snr, rssi, hop): elif "pong" in message.lower(): bot_response = "PING!!" elif "motd" in message.lower(): - #check if the user wants to set the motd by using $ + # check if the user wants to set the motd by using $ if "$" in message: motd = message.split("$")[1] global MOTD @@ -130,7 +130,7 @@ def onReceive(packet, interface): # respond with a direct message send_message(auto_response(message_string,snr,rssi,hop),channel_number,message_from_id) else: - #respond with welcome message + # respond with welcome message print(f"{log_timestamp()} Ignoring DM: {message_string} From: {get_name_from_number(message_from_id)}") send_message(welcome_message,channel_number,message_from_id) else: @@ -189,7 +189,7 @@ def get_node_list(): # issue where lastHeard is not always present last_heard = node.get('lastHeard', 0) - #make a list of nodes with last heard time and SNR + # make a list of nodes with last heard time and SNR item = (node_name, last_heard, snr) node_list.append(item) @@ -206,7 +206,7 @@ def get_node_list(): return "Error Processing Node List" def send_message(message, ch, nodeid): - #if message over 160 characters, split it into multiple messages + # 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)] # smarter word split @@ -220,24 +220,24 @@ def send_message(message, ch, nodeid): else: message_list.append(line) line = word + ' ' - message_list.append(line) #needed add contents of the last 'line' into the list + message_list.append(line) # needed add contents of the last 'line' into the list for m in message_list: if nodeid == 0: - #Send to channel + # Send to channel print (f"{log_timestamp()} System: Sending Multi-Chunk: {m} To: Channel:{ch}") interface.sendText(text=m, channelIndex=ch) else: - #Send to DM + # Send to DM print (f"{log_timestamp()} System: Sending Multi-Chunk: {m} To: {get_name_from_number(nodeid)}") interface.sendText(text=m,channelIndex=ch, destinationId=nodeid) - else: #message is less than 160 characters + else: # message is less than 160 characters if nodeid == 0: - #Send to channel + # Send to channel print (f"{log_timestamp()} System: Sending: {message} To: Channel:{ch}") interface.sendText(text=message, channelIndex=ch) else: - #Send to DM + # Send to DM print (f"{log_timestamp()} System: Sending: {message} To: {get_name_from_number(nodeid)}") interface.sendText(text=message, channelIndex=ch, destinationId=nodeid) diff --git a/solarconditions.py b/solarconditions.py index f20a1a2..3644932 100644 --- a/solarconditions.py +++ b/solarconditions.py @@ -81,7 +81,7 @@ def get_sun(lat=0, lon=0): local_sunset = ephem.localtime(obs.next_setting(sun)) sun_table['rise_time'] = local_sunrise.strftime('%a %d %I:%M') sun_table['set_time'] = local_sunset.strftime('%a %d %I:%M') - #if sunset is before sunrise, then it's tomorrow + # if sunset is before sunrise, then it's tomorrow if local_sunset < local_sunrise: local_sunset = ephem.localtime(obs.next_setting(sun)) + timedelta(1) sun_table['set_time'] = local_sunset.strftime('%a %d %I:%M')