Skip to content

Commit

Permalink
Guide for severe weather warning in README
Browse files Browse the repository at this point in the history
  • Loading branch information
mendhak committed Mar 6, 2022
1 parent fcaeb77 commit 61c35ab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2022-03-06
* Add weather.gov as a forecast and alert provider

## 2022-01-07

* Add cryptography==36.0.0 to setup. It's used by msal, but version 36.0.1 from piwheels produces [illegal instruction](https://github.com/piwheels/packages/issues/273)
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ As needed, change the temperature format (CELSIUS or FAHRENHEIT).
export WEATHER_LONGITUDE=0.1963
export WEATHER_FORMAT=CELSIUS

## Pick a severe weather warning provider

### Met Office (UK)

Go to the [Met Office RSS Feeds page](https://www.metoffice.gov.uk/weather/guides/rss) and pick the RSS feed based on your region.
Set its value in the `env.sh` as `ALERT_METOFFICE_FEED_URL`. For example, London would be:

export ALERT_METOFFICE_FEED_URL=https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/se

### Weather.gov (US)

Weather.gov requires you to [identify your application](https://www.weather.gov/documentation/services-web-api). This can be any made up string, or an email address.

export [email protected]

This provider will use the same latitude and longitude as specified for the weather provider.


## Pick a Calendar provider

Expand Down
19 changes: 11 additions & 8 deletions alert_providers/weathergovalerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ def __init__(self, location_lat, location_long, weathergov_self_id):


def get_alert(self):
severe = self.get_response_json("https://api.weather.gov/alerts?point={},{}".format(self.location_lat, self.location_long),
headers={'User-Agent':'({0})'.format(self.weathergov_self_id)})
logging.debug("get_alert - {}".format(severe))
if 'features' in severe:
if 'properties' in severe["features"][0]:
if 'parameters' in severe["features"][0]["properties"]:
if 'NWSheadline' in severe["features"][0]["properties"]["parameters"]:
return severe["features"][0]["properties"]["parameters"]["NWSheadline"][0]
try:
severe = self.get_response_json("https://api.weather.gov/alerts?point={},{}".format(self.location_lat, self.location_long),
headers={'User-Agent':'({0})'.format(self.weathergov_self_id)})
logging.debug("get_alert - {}".format(severe))
if 'features' in severe:
if 'properties' in severe["features"][0]:
if 'parameters' in severe["features"][0]["properties"]:
if 'NWSheadline' in severe["features"][0]["properties"]["parameters"]:
return severe["features"][0]["properties"]["parameters"]["NWSheadline"][0]
except Exception as error:
pass
return ""

0 comments on commit 61c35ab

Please sign in to comment.