def command(self, fromcall, message, ack): LOG.info("Weather Plugin") try: utils.check_config_option(self.config, ["services", "aprs.fi", "apiKey"]) except Exception as ex: LOG.error("Failed to find config aprs.fi:apikey {}".format(ex)) return "No aprs.fi apikey found" api_key = self.config["services"]["aprs.fi"]["apiKey"] try: aprs_data = plugin_utils.get_aprs_fi(api_key, fromcall) except Exception as ex: LOG.error("Failed to fetch aprs.fi data {}".format(ex)) return "Failed to fetch location" # LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data)) lat = aprs_data["entries"][0]["lat"] lon = aprs_data["entries"][0]["lng"] try: wx_data = plugin_utils.get_weather_gov_for_gps(lat, lon) except Exception as ex: LOG.error("Couldn't fetch forecast.weather.gov '{}'".format(ex)) return "Unable to get weather" reply = ( "%sF(%sF/%sF) %s. %s, %s." % ( wx_data["currentobservation"]["Temp"], wx_data["data"]["temperature"][0], wx_data["data"]["temperature"][1], wx_data["data"]["weather"][0], wx_data["time"]["startPeriodName"][1], wx_data["data"]["weather"][1], ) ).rstrip() LOG.debug("reply: '{}' ".format(reply)) return reply
def process(self, packet): LOG.info("Weather Plugin") fromcall = packet.get("from") # message = packet.get("message_text", None) # ack = packet.get("msgNo", "0") api_key = self.config["services"]["aprs.fi"]["apiKey"] try: aprs_data = plugin_utils.get_aprs_fi(api_key, fromcall) except Exception as ex: LOG.error(f"Failed to fetch aprs.fi data {ex}") return "Failed to fetch aprs.fi location" LOG.debug(f"LocationPlugin: aprs_data = {aprs_data}") if not len(aprs_data["entries"]): LOG.error("Didn't get any entries from aprs.fi") return "Failed to fetch aprs.fi location" lat = aprs_data["entries"][0]["lat"] lon = aprs_data["entries"][0]["lng"] try: wx_data = plugin_utils.get_weather_gov_for_gps(lat, lon) except Exception as ex: LOG.error(f"Couldn't fetch forecast.weather.gov '{ex}'") return "Unable to get weather" reply = ("%sF(%sF/%sF) %s. %s, %s." % ( wx_data["currentobservation"]["Temp"], wx_data["data"]["temperature"][0], wx_data["data"]["temperature"][1], wx_data["data"]["weather"][0], wx_data["time"]["startPeriodName"][1], wx_data["data"]["weather"][1], )).rstrip() LOG.debug(f"reply: '{reply}' ") return reply
def process(self, packet): LOG.info("Location Plugin") fromcall = packet.get("from") message = packet.get("message_text", None) # ack = packet.get("msgNo", "0") api_key = self.config["services"]["aprs.fi"]["apiKey"] # optional second argument is a callsign to search a = re.search(r"^.*\s+(.*)", message) if a is not None: searchcall = a.group(1) searchcall = searchcall.upper() else: # if no second argument, search for calling station searchcall = fromcall try: aprs_data = plugin_utils.get_aprs_fi(api_key, searchcall) except Exception as ex: LOG.error(f"Failed to fetch aprs.fi '{ex}'") return "Failed to fetch aprs.fi location" LOG.debug(f"LocationPlugin: aprs_data = {aprs_data}") if not len(aprs_data["entries"]): LOG.error("Didn't get any entries from aprs.fi") return "Failed to fetch aprs.fi location" lat = aprs_data["entries"][0]["lat"] lon = aprs_data["entries"][0]["lng"] try: # altitude not always provided alt = float(aprs_data["entries"][0]["altitude"]) except Exception: alt = 0 altfeet = int(alt * 3.28084) aprs_lasttime_seconds = aprs_data["entries"][0]["lasttime"] # aprs_lasttime_seconds = aprs_lasttime_seconds.encode( # "ascii", errors="ignore" # ) # unicode to ascii delta_seconds = time.time() - int(aprs_lasttime_seconds) delta_hours = delta_seconds / 60 / 60 try: wx_data = plugin_utils.get_weather_gov_for_gps(lat, lon) except Exception as ex: LOG.error(f"Couldn't fetch forecast.weather.gov '{ex}'") wx_data = {"location": {"areaDescription": "Unknown Location"}} if "location" not in wx_data: LOG.error(f"Couldn't fetch forecast.weather.gov '{wx_data}'") wx_data = {"location": {"areaDescription": "Unknown Location"}} reply = "{}: {} {}' {},{} {}h ago".format( searchcall, wx_data["location"]["areaDescription"], str(altfeet), str(lat), str(lon), str("%.1f" % round(delta_hours, 1)), ).rstrip() return reply
def process(self, packet): LOG.info("SlackCommandPlugin") fromcall = packet["from"] message = packet["message_text"] is_setup = self.setup_slack() if not is_setup: return # get last location of a callsign, get descriptive name from weather service try: self.config.exists(["services", "aprs.fi", "apiKey"]) except Exception as ex: LOG.error("Failed to find config aprs.fi:apikey {}".format(ex)) return "No aprs.fi apikey found" api_key = self.config["services"]["aprs.fi"]["apiKey"] # optional second argument is a callsign to search a = re.search(r"^.*\s+(.*)", message) if a is not None: searchcall = a.group(1) searchcall = searchcall.upper() else: # if no second argument, search for calling station searchcall = fromcall try: aprs_data = plugin_utils.get_aprs_fi(api_key, searchcall) except Exception as ex: LOG.error("Failed to fetch aprs.fi '{}'".format(ex)) return "Failed to fetch aprs.fi location" LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data)) if not len(aprs_data["entries"]): LOG.error("Didn't get any entries from aprs.fi") return "Failed to fetch aprs.fi location" lat = aprs_data["entries"][0]["lat"] lon = aprs_data["entries"][0]["lng"] try: # altitude not always provided alt = float(aprs_data["entries"][0]["altitude"]) except Exception: alt = 0 altfeet = int(alt * 3.28084) aprs_lasttime_seconds = aprs_data["entries"][0]["lasttime"] delta_seconds = time.time() - int(aprs_lasttime_seconds) delta_hours = delta_seconds / 60 / 60 wx_data = None try: wx_data = plugin_utils.get_weather_gov_for_gps(lat, lon) except Exception: LOG.warning("Couldn't fetch forecast.weather.gov") callsign_url = "<http://aprs.fi/info/a/{}|{}>".format( searchcall, searchcall) aprs_url = "<http://aprs.fi/#!mt=roadmap&z=15&lat={}&lng={}|" " http://aprs.fi/>".format( lat, lon, ) message = {} message["username"] = "******" message["icon_emoji"] = ":satellite_antenna:" message["attachments"] = [{}] message["text"] = "{} - Location".format(callsign_url) message["channel"] = "#random" attachment = message["attachments"][0] attachment["fallback"] = message["text"] attachment["fields"] = [] # if the coordinates are outside of the US, we don't get this # aread description if wx_data and "location" in wx_data and "areaDescription" in wx_data[ "location"]: attachment["fields"].append( { "title": "Location", "value": wx_data["location"]["areaDescription"], "short": True, }, ) attachment["fields"].append( { "title": "Map Location", "value": aprs_url, "short": True }, ) attachment["fields"].append( { "title": "Altitude", "value": altfeet, "short": True, "fallback": "Altitude - {}".format(altfeet), }, ) attachment["fields"].append( { "title": "Time", "value": "{} h ago".format(round(delta_hours, 1)), "short": True, "fallback": "Time {} h ago".format(round(delta_hours, 1)), }, ) LOG.debug(message) # self.swc.chat_postMessage(**message) for channel in self.slack_channels: message["channel"] = channel self.swc.chat_postMessage(**message) # Don't have aprsd try and send a reply return messaging.NULL_MESSAGE
def command(self, fromcall, message, ack): LOG.info("Location Plugin") # get last location of a callsign, get descriptive name from weather service try: utils.check_config_option(self.config, ["services", "aprs.fi", "apiKey"]) except Exception as ex: LOG.error("Failed to find config aprs.fi:apikey {}".format(ex)) return "No aprs.fi apikey found" api_key = self.config["services"]["aprs.fi"]["apiKey"] # optional second argument is a callsign to search a = re.search(r"^.*\s+(.*)", message) if a is not None: searchcall = a.group(1) searchcall = searchcall.upper() else: # if no second argument, search for calling station searchcall = fromcall try: aprs_data = plugin_utils.get_aprs_fi(api_key, searchcall) except Exception as ex: LOG.error("Failed to fetch aprs.fi '{}'".format(ex)) return "Failed to fetch aprs.fi location" LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data)) if not len(aprs_data["entries"]): LOG.error("Didn't get any entries from aprs.fi") return "Failed to fetch aprs.fi location" lat = aprs_data["entries"][0]["lat"] lon = aprs_data["entries"][0]["lng"] try: # altitude not always provided alt = float(aprs_data["entries"][0]["altitude"]) except Exception: alt = 0 altfeet = int(alt * 3.28084) aprs_lasttime_seconds = aprs_data["entries"][0]["lasttime"] # aprs_lasttime_seconds = aprs_lasttime_seconds.encode( # "ascii", errors="ignore" # ) # unicode to ascii delta_seconds = time.time() - int(aprs_lasttime_seconds) delta_hours = delta_seconds / 60 / 60 try: wx_data = plugin_utils.get_weather_gov_for_gps(lat, lon) except Exception as ex: LOG.error("Couldn't fetch forecast.weather.gov '{}'".format(ex)) wx_data = {"location": {"areaDescription": "Unknown Location"}} if "location" not in wx_data: LOG.error( "Couldn't fetch forecast.weather.gov '{}'".format(wx_data)) wx_data = {"location": {"areaDescription": "Unknown Location"}} reply = "{}: {} {}' {},{} {}h ago".format( searchcall, wx_data["location"]["areaDescription"], str(altfeet), str(lat), str(lon), str("%.1f" % round(delta_hours, 1)), ).rstrip() return reply
def command(self, fromcall, message, ack): LOG.info("WX Plugin '{}'".format(message)) a = re.search(r"^.*\s+(.*)", message) if a is not None: searchcall = a.group(1) station = searchcall.upper() try: resp = plugin_utils.get_weather_gov_metar(station) except Exception as e: LOG.debug("Weather failed with: {}".format(str(e))) reply = "Unable to find station METAR" else: station_data = json.loads(resp.text) reply = station_data["properties"]["rawMessage"] return reply else: # if no second argument, search for calling station fromcall = fromcall try: utils.check_config_option( self.config, ["services", "aprs.fi", "apiKey"], ) except Exception as ex: LOG.error("Failed to find config aprs.fi:apikey {}".format(ex)) return "No aprs.fi apikey found" api_key = self.config["services"]["aprs.fi"]["apiKey"] try: aprs_data = plugin_utils.get_aprs_fi(api_key, fromcall) except Exception as ex: LOG.error("Failed to fetch aprs.fi data {}".format(ex)) return "Failed to fetch location" # LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data)) if not len(aprs_data["entries"]): LOG.error("Found no entries from aprs.fi!") return "Failed to fetch location" lat = aprs_data["entries"][0]["lat"] lon = aprs_data["entries"][0]["lng"] try: wx_data = plugin_utils.get_weather_gov_for_gps(lat, lon) except Exception as ex: LOG.error("Couldn't fetch forecast.weather.gov '{}'".format(ex)) return "Unable to metar find station." if wx_data["location"]["metar"]: station = wx_data["location"]["metar"] try: resp = plugin_utils.get_weather_gov_metar(station) except Exception as e: LOG.debug("Weather failed with: {}".format(str(e))) reply = "Failed to get Metar" else: station_data = json.loads(resp.text) reply = station_data["properties"]["rawMessage"] else: # Couldn't find a station reply = "No Metar station found" return reply
def process(self, packet): fromcall = packet.get("from") message = packet.get("message_text", None) # ack = packet.get("msgNo", "0") LOG.info(f"WX Plugin '{message}'") a = re.search(r"^.*\s+(.*)", message) if a is not None: searchcall = a.group(1) station = searchcall.upper() try: resp = plugin_utils.get_weather_gov_metar(station) except Exception as e: LOG.debug(f"Weather failed with: {str(e)}") reply = "Unable to find station METAR" else: station_data = json.loads(resp.text) reply = station_data["properties"]["rawMessage"] return reply else: # if no second argument, search for calling station fromcall = fromcall try: self.config.exists(["services", "aprs.fi", "apiKey"]) except Exception as ex: LOG.error(f"Failed to find config aprs.fi:apikey {ex}") return "No aprs.fi apikey found" api_key = self.config["services"]["aprs.fi"]["apiKey"] try: aprs_data = plugin_utils.get_aprs_fi(api_key, fromcall) except Exception as ex: LOG.error(f"Failed to fetch aprs.fi data {ex}") return "Failed to fetch aprs.fi location" # LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data)) if not len(aprs_data["entries"]): LOG.error("Found no entries from aprs.fi!") return "Failed to fetch aprs.fi location" lat = aprs_data["entries"][0]["lat"] lon = aprs_data["entries"][0]["lng"] try: wx_data = plugin_utils.get_weather_gov_for_gps(lat, lon) except Exception as ex: LOG.error(f"Couldn't fetch forecast.weather.gov '{ex}'") return "Unable to metar find station." if wx_data["location"]["metar"]: station = wx_data["location"]["metar"] try: resp = plugin_utils.get_weather_gov_metar(station) except Exception as e: LOG.debug(f"Weather failed with: {str(e)}") reply = "Failed to get Metar" else: station_data = json.loads(resp.text) reply = station_data["properties"]["rawMessage"] else: # Couldn't find a station reply = "No Metar station found" return reply