def test_passing_samecodes(self): # Alerts by a Samecode testobjs = [] testobjs.append(WeatherAlerts(samecodes='016027')) testobjs.append( WeatherAlerts(samecodes=['016027', '016001', '016073', '016075'])) samecodes = list( self.nws.geo.samecodes.keys()) # will return dict_keys obj in py3 testobjs.append( WeatherAlerts(samecodes=samecodes)) # use them for testing for nws in testobjs: for alert in nws.alerts: x = alert.title x = alert.summary x = alert.areadesc x = alert.event x = alert.samecodes x = alert.zonecodes x = alert.expiration x = alert.updated x = alert.effective x = alert.published x = alert.severity x = alert.category x = alert.urgency
async def severe(self, ctx): """Gets any Severe Weather Reports for Ames and Des Moines.""" result = "Ames:\n" nws = WeatherAlerts(samecodes='019169') for alert in nws.alerts: result = result + alert.title + "\n" result = result + "\nDes Moines:\n" nws = WeatherAlerts(samecodes='019153') for alert in nws.alerts: result = result + alert.title + "\n" await self.bot.say(result)
def update_noaa_statuses(): hudson_county_alerts = WeatherAlerts(samecodes=SAMECODE).alerts if hudson_county_alerts: for alert in hudson_county_alerts: if alert.category == "Met": logging.info("Weather alert for %s: %s", alert.areadesc, alert.title) # pylint: disable=assignment-from-no-return existing_alert = NOAA_status.select().where( NOAA_status.url == alert.link) if not existing_alert.exists(): NOAA_status(severity=alert.severity, summary=alert.summary, status=alert.title, urgency=alert.urgency, effective=alert.effective, expiration=alert.expiration, published=alert.published, updated=alert.updated, areadesc=alert.areadesc, url=alert.link).save() else: logging.info("Skipping previously observed alert") else: logging.info("No NOAA alerts")
def test_break_on_samecodes(self): '''break if you pass in non str/list samecodes''' try: nws = WeatherAlerts(samecodes=1) except Exception: pass else: raise Exception("That shouldn't have worked")
def checkTheWeather(**whereAmI): # read samecodes every time and grab any alerts from NOAA # if weather is bad and unACKED call ifWeatherIsBad print('Checking in with ' + whereAmI['name']) NOAAalerts = WeatherAlerts(whereAmI['samecode']) allAlerts = [] for alert in NOAAalerts.alerts: allAlerts.append(alert.title) return whereAmI
def update(self): from weatheralerts import WeatherAlerts nws = WeatherAlerts(samecodes=self._sameid) self._published = nws.alerts[0].published self._state = nws.alerts[0].event self._urgency = nws.alerts[0].urgency self._severity = nws.alerts[0].severity self._category = nws.alerts[0].category self._title = nws.alerts[0].title self._summary = nws.alerts[0].summary self._link = nws.alerts[0].link
def test_passing_state(self): nws = WeatherAlerts(state='ID') for alert in nws.alerts: x = alert.title x = alert.summary x = alert.areadesc x = alert.event x = alert.samecodes x = alert.zonecodes x = alert.expiration x = alert.updated x = alert.effective x = alert.published x = alert.severity x = alert.category x = alert.urgency
def CheckForAlerts(): logging.warning( '-------------------------------------------------------------------') global Started global Posted Alert_to_Post = [] # once every 24hrs clear the Posted list if (time.time() - Started) >= 86400: Posted = [] Started = time.time() # check for alerts for the counties privieded for q in Counties_in_State: for currentState, Counties in q.items(): nws = WeatherAlerts(state=currentState) for alert in nws.alerts: for currentCounty in Counties: Is_Posted = False if currentCounty in alert.areadesc: Alert = [ alert.severity, [currentCounty], alert.title, alert.summary ] logging.debug('Alert = {}'.format(Alert)) try: if Alert not in Alert_to_Post: if Alert_to_Post == []: Alert_to_Post.append(Alert) logging.debug( "Alert to post empty, adding to alert to post. {}" .format(alert)) Is_Posted = True else: for i in Alert_to_Post: if (i[2] == Alert[2]) and (i[3] == Alert[3]): if currentCounty not in i[1]: i[1].append(currentCounty) Is_Posted = True if Is_Posted == False: Alert_to_Post.append(Alert) logging.debug( "Alert doesn't match any found. {}" .format(alert)) Is_Posted = True except Exception: Alert_to_Post.append(Alert) logging.debug( "Try error, adding to alert to post. {}". format(alert)) logging.debug('Alert_to_Post = {}'.format(Alert_to_Post)) # check if alert has been posted if Posted == []: for new_alert in Alert_to_Post: tempList = [] tempList4 = [] for i in new_alert[1]: tempList.append(i) for i in tempList: for z in Cities_in_County: for county, city in z.items(): if county in i: for m in city: tempList4.append(m) cities_affected = ' @{}'.format(' @'.join(tempList4)) msg = "**{}** - {} - {}".format(new_alert[2], new_alert[3], cities_affected) send(channel_id, msg) Posted.append(new_alert) else: for new_alert in Alert_to_Post: tempList4 = [] if new_alert not in Posted: tempList = [] for i in new_alert[1]: tempList.append(i) for i in tempList: for z in Cities_in_County: for county, city in z.items(): if county in i: for m in city: tempList4.append(m) cities_affected = ' @{}'.format(' @'.join(tempList4)) msg = "**{}** - {} - {}".format(new_alert[2], new_alert[3], cities_affected) send(channel_id, msg) Posted.append(new_alert)
#!/usr/bin/env python from time import sleep from weatheralerts import WeatherAlerts if __name__ == "__main__": nws = WeatherAlerts(state='ID', cachetime=1) for alert in nws.alerts: print "{0}: {1}".format(alert.areadesc, alert.title) nws = WeatherAlerts(cachetime=1) print len(nws.alerts) print len(nws.alerts) sleep(70) nws.refresh(force=True) print len(nws.alerts)
class Test_WeatherAlerts(unittest.TestCase): def setUp(self): self.nws = WeatherAlerts() def test_almost_everything(self): print("Alerts currently in feed {0}".format(len(self.nws.alerts))) def test_event_state_counties(self): self.nws.event_state_counties() def test_samecode_alerts_method(self): self.nws.samecode_alerts('016027') def test_refresh(self): self.nws.refresh() def test_refresh_forced(self): self.nws.refresh(force=True) def test_county_state_alerts(self): self.nws.county_state_alerts('canyon', 'ID') def test_alert_attributes(self): for alert in self.nws.alerts: x = alert.title x = alert.summary x = alert.areadesc x = alert.event x = alert.samecodes x = alert.zonecodes x = alert.expiration x = alert.updated x = alert.effective x = alert.published x = alert.severity x = alert.category x = alert.urgency def test_passing_samecodes(self): # Alerts by a Samecode testobjs = [] testobjs.append(WeatherAlerts(samecodes='016027')) testobjs.append( WeatherAlerts(samecodes=['016027', '016001', '016073', '016075'])) samecodes = list( self.nws.geo.samecodes.keys()) # will return dict_keys obj in py3 testobjs.append( WeatherAlerts(samecodes=samecodes)) # use them for testing for nws in testobjs: for alert in nws.alerts: x = alert.title x = alert.summary x = alert.areadesc x = alert.event x = alert.samecodes x = alert.zonecodes x = alert.expiration x = alert.updated x = alert.effective x = alert.published x = alert.severity x = alert.category x = alert.urgency def test_passing_state(self): nws = WeatherAlerts(state='ID') for alert in nws.alerts: x = alert.title x = alert.summary x = alert.areadesc x = alert.event x = alert.samecodes x = alert.zonecodes x = alert.expiration x = alert.updated x = alert.effective x = alert.published x = alert.severity x = alert.category x = alert.urgency def test_break_on_samecodes(self): '''break if you pass in non str/list samecodes''' try: nws = WeatherAlerts(samecodes=1) except Exception: pass else: raise Exception("That shouldn't have worked")
def setUp(self): self.nws = WeatherAlerts()
async def async_update(self): # pylint: disable=missing-docstring from weatheralerts import WeatherAlerts current = {"state": self._state, "attributes": self._attr} try: nws = None last_event = None try: nws = WeatherAlerts(samecodes=self._sameid) except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) if nws is None: try: nws = WeatherAlerts(samecodes=self._sameid) except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) if nws is None: try: nws = WeatherAlerts(samecodes=self._sameid) except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) if nws is None: try: nws = WeatherAlerts(samecodes=self._sameid) except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) if nws is None: try: nws = WeatherAlerts(samecodes=self._sameid) except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) last_event = nws.alerts[0] if last_event is not None: try: self._state = last_event.event except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) try: self._attr["published"] = last_event.published except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) try: self._attr["urgency"] = last_event.urgency except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) try: self._attr["category"] = last_event.category except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) try: self._attr["title"] = last_event.title except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) try: self._attr["summary"] = last_event.summary except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) try: self._attr["link"] = last_event.link except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) except Exception as error: # pylint: disable=broad-except _LOGGER.error(error) self._state = current.get("state") self._attr = current.get("attributes")
# Configure SMS here. # sms_type, 0 = private, 1 = group # sms_format, 0 = ETSI, 1 = UDP, 2 = UDP/Chinese # sms_dest, Talk group or DMR ID # sms_modem, 0 = Network, send SMS to the network, 1 = Modem, send SMS to modem only, # will not get sent to network sms_type = "1" sms_format = "2" sms_dest = "9" sms_modem = "1" shark.do_checkauth() # Same codes for Chelan, Douglas, Grant, and Okanogan Counties nws = WeatherAlerts(samecodes=['053007', '053017', '053025', '053047']) # Same codes for entire state #nws = WeatherAlerts(state='WA') # Filter for Severe alerts for alert in nws.alerts: if "Severe" in alert.severity: # 1=Type, Group | 2=Format, UDP/Chinese | 9=Talkgroup | alert.title= message shark.do_send_sms(sms_type, sms_format, sms_dest, sms_modem, alert.title) print(alert.title) print(alert.severity) print(alert.urgency) print(alert.areadesc) print(alert.samecodes)