Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zebpalmer committed Mar 11, 2013
1 parent 707a934 commit 2fba7ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 5 additions & 1 deletion weatheralerts/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
self._save_feed_cache(raw)
return raw



def _get_nws_feed(self):
'''get nws alert feed, and cache it'''
url = '''http://alerts.weather.gov/cap/%s.php?x=0''' % (self._state)
Expand Down
2 changes: 1 addition & 1 deletion weatheralerts/test_weatheralerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
self.nws.event_state_counties()
Expand Down
19 changes: 11 additions & 8 deletions weatheralerts/weather_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ class WeatherAlerts(object):
'''
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
*Defaults to National Feed, it can be quite large at times, you probably don't want to parse it very often.
*Set a 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. This will
pull your state feed automatically.
'''
self._alerts = None
self._feed = None
Expand Down Expand Up @@ -59,6 +62,10 @@ def refresh(self, force=False):

@property
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:
Expand All @@ -69,13 +76,9 @@ def alerts(self):
else:
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):
Expand Down

0 comments on commit 2fba7ed

Please sign in to comment.