Browse files


  • Loading branch information...
2 parents 035904d + 3a287d8 commit 93a7cfde5f07f194134b6cbd3538862520086eed @zebpalmer committed Mar 11, 2013
4 docs/module.rst
@@ -13,6 +13,10 @@ Below you'll find the documentation for the various classes and methods in Weath
+.. automodule:: weather_alerts
+ :members:
+ :undoc-members:
.. automodule:: geo
3 weatheralerts/
@@ -11,7 +11,8 @@
**Original Author:**
- Zeb Palmer
+ Zeb Palmer
6 weatheralerts/
@@ -46,12 +46,16 @@ def raw_cap(self, refresh=False):
def refresh(self):
- Refresh the feed bypassing the cache
+ NOTE: You probably don't want to call this... This does not update the alerts loaded
+ in the WeatherAlerts object, only the underlying feed. This is only used internally now and as such,
+ will likely be deprecated soon. Please call `WeatherAlerts.refresh()` instead.
raw = self._get_nws_feed()
return raw
def _get_nws_feed(self):
'''get nws alert feed, and cache it'''
url = '''''' % (self._state)
3 weatheralerts/
@@ -19,6 +19,7 @@ def __init__(self):
def location_lookup(self, req_location):
returns full location given samecode or county and state. Returns False if not valid.
*currently locations are a dictionary, once other geo data is added, they will move to a location class/obj*
location = False
@@ -62,6 +63,7 @@ def getfeedscope(self, geocodes):
def _get_states_from_samecodes(self, geocodes):
'''Returns all states for a given list of SAME codes
*Shouldn't be used to determine feed scope, please use getfeedscope()*
states = []
@@ -81,6 +83,7 @@ def _get_states_from_samecodes(self, geocodes):
class SameCodes(object):
Is used to download, parse and cache the SAME codes data from the web.
*All interaction with the SAME codes data should be done with the GeoGB object*
def __init__(self):
2 weatheralerts/
@@ -8,7 +8,7 @@ def setUp(self):
self.nws = WeatherAlerts()
def test_almost_everything(self):
- print "Alerts currently in feed {0}".format(self.nws.alert_count)
+ print "Alerts currently in feed {0}".format(len(self.nws.alerts))
def test_event_state_counties(self):
27 weatheralerts/
@@ -7,13 +7,18 @@
class WeatherAlerts(object):
WeatherAlerts object that controls interaction with the NWS CAP alerts feed as well and varios geo data sources.
- Most interaction from users, scripts, etc will be through the api provided by this class. So, as we approach a
- more stable project, the API in this class will also become more stable and maintain backwards compatibility.
+ Most interaction from users, scripts, etc will be through the api provided by this `WeatherAlerts` class.
+ So, as we approach a more stable project, the API in this class will also become more stable.
+ * Defaults to National Feed, it can be quite large at times, you probably don't want to parse it very often.
+ * Set `state` to see all alerts on your state feed.
+ * For local alerts only, set `samecodes` to a single samecode string, or list of samecode strings.
+ * `cachetime` is set in minutes, default is 3.
def __init__(self, state=None, samecodes=None, load=True, cachetime=3):
- init Alerts, default to National Feed, set state level samecodes or county codes the area in which you want to
- load alerts.
+ WeatherAlerts Init
self._alerts = None
self._feed = None
@@ -50,7 +55,7 @@ def load_alerts(self):
def refresh(self, force=False):
- Refresh the alerts list. set force=true to force pulling a new list from the NWS. if force=false (default)
+ Refresh the alerts list. set `force` to True to force pulling a new list from the NWS, otherwise
it'll only pull a new list if the cached copy is expired. (see cachetime)
if force is True:
@@ -59,6 +64,10 @@ def refresh(self, force=False):
def alerts(self):
+ '''returns the alerts list. If samecode(s) are specified when the WeatherAlerts object is created,
+ this will only return alerts for those samecodes. If no samecodes were given, it'll return all alerts for the
+ state if one was specified otherwise for the entire U.S.
+ '''
if self.samecodes is not None:
temp = []
for alert in self._alerts:
@@ -69,13 +78,9 @@ def alerts(self):
return self._alerts
- @property
- def alert_count(self):
- '''simple property for checking the number of alerts, mainly for debugging purposes'''
- return len(self._alerts)
def samecode_alerts(self, samecode):
- '''Returns alerts for specified SAME geocodes'''
+ '''Returns alerts for a ()single) SAME geocode. Only useful if you didn't specify samecodes when the WeatherAlerts
+ object was created.'''
return [x for x in self._alerts if samecode in x.samecodes]
def county_state_alerts(self, county, state):

0 comments on commit 93a7cfd

Please sign in to comment.