Permalink
Browse files

0.5.0rc2

  • Loading branch information...
2 parents d26101e + 88a34e3 commit 035904d357eb3ac5b541140c72e50ec3bafcc8a5 @zebpalmer committed Mar 11, 2013
View
@@ -2,16 +2,17 @@
Release Changes
===============
-Current Development is on the 5.0 version
+Current Development is on 5.x
-**0.5.0** (*Current Release*)
+**0.5.0rc**
* 100% Test Coverage
* building python3 version at install, no longer maintaining separate code
* rewrite
* improved API organization
* improved documentation
* relicensed under LGPLv3
+* reworked refresh logic (thanks to Michael W. for bug report)
Older Versions
@@ -21,7 +22,7 @@ Versions prior to 0.5.x are no longer supported. It is suggest you test and upgr
-**v0.4.9**
+**v0.4.9**
* Last of the 4.x branch
* rather large changes to classes
View
@@ -2,13 +2,6 @@ Code Documentation
*********************
-.. Note::
- You're looking at documentation for the development version of WeatherAlerts. If you're looking for documentation
- for the latest stable release (what's currently in pypi) click `v0.4.9 <http://weatheralerts.readthedocs.org/en/v0.4.9/>`_
-
-
-
-
Below you'll find the documentation for the various classes and methods in WeatherAlerts.
.. Note::
View
@@ -4,8 +4,8 @@ National Weather Service Alert Data
Overview
------------
-This package pulls in 'near realtime' alert data from the National Weather Service (NWS) CAP index feed. It's an ATOM/XML
-feed with additional CAP 1.1 defined fields.
+This package pulls in 'near realtime' alert data from the National Weather Service (NWS) CAP index feed. It's an
+ATOM/XML feed with additional CAP 1.1 defined fields.
@@ -18,8 +18,8 @@ SAME Codes and Geo Location
.............................
Currently this project makes extensive use of SAME codes, it's been noted that 'not all NWS products are issued with a
SAME Code'. However, 'County/Zone codes are provided for all CAP 1.1 messages.' I've noticed that a lot of Alaskan
-alerts do not ship with SAME codes, some don't appear to ship with any geocodes... Most lower 48 alerts do, in fact,
-I haven't seen one that didn't. For this reason though, we'll be incorperating county/zone codes and Storm based
+alerts do not ship with SAME codes, some don't appear to ship with any geocodes... Most lower 48 alerts do, in fact,
+I haven't seen one that didn't. For this reason though, we'll be incorperating county/zone codes and Storm based
location information in the near future.
View
@@ -5,8 +5,8 @@ Using WeatherAlerts
Simple example
===============
-This are three examples of the simplest implementation, import the WeatherAlerts class, create an instance requesting alerts for
-an area based on one or more SAMECODES or bt requesting an entire State.
+This are three examples of the simplest implementation, import the WeatherAlerts class, create an instance requesting
+alerts for an area based on one or more SAMECODES or bt requesting an entire State.
.. code-block:: python
View
@@ -1,14 +1,21 @@
#!/usr/bin/env python
-
+from time import sleep
from weatheralerts import WeatherAlerts
if __name__ == "__main__":
- nws = WeatherAlerts(state='ID')
- for alert in nws.alerts:
- print "{0}: {1}".format(alert.areadesc, alert.title)
+ 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)
View
@@ -5,7 +5,7 @@
import sys
-versionstr = '0.5.0rc1'
+versionstr = '0.5.0rc2'
setup(
View
@@ -8,7 +8,7 @@ class CapParser(object):
'''
Parses the xml from the alert feed, creates and returns a list of alert objects.
- FIXME: This is slow, messy, and painful to look at.
+ FIXME: This is slow, messy, and painful to look at. I'll be totally rewriting it shortly.
'''
def __init__(self, raw_cap, geo=None):
View
@@ -37,6 +37,7 @@ def raw_cap(self, refresh=False):
'''
Raw xml(cap) of the the feed. If a valid cache is availible
it is used, else a new copy of the feed is grabbed
+ Note: you can force refresh here, if you do, don't also manually call refresh
'''
raw = self._get_feed_cache()
if raw is None or refresh is True:
@@ -5,7 +5,7 @@
class Test_Feed(unittest.TestCase):
def setUp(self):
- self.cf = AlertsFeed(maxage=60)
+ self.cf = AlertsFeed(maxage=5)
def test_refesh(self):
self.cf.raw_cap(refresh=True)
@@ -16,6 +16,12 @@ def test_event_state_counties(self):
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')
@@ -37,22 +43,26 @@ def test_alert_attributes(self):
def test_passing_samecodes(self):
# Alerts by a Samecode
- nws = WeatherAlerts(samecodes='016027')
- nws = WeatherAlerts(samecodes=['016027', '016001', '016073', '016075'])
- 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
+ testobjs = []
+ testobjs.append(WeatherAlerts(samecodes='016027'))
+ testobjs.append(WeatherAlerts(samecodes=['016027', '016001', '016073', '016075']))
+ samecodes = self.nws.geo.samecodes.keys() # get list of all known samecodes
+ 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')
@@ -10,15 +10,17 @@ class WeatherAlerts(object):
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.
'''
- def __init__(self, state=None, samecodes=None, load=True):
+ 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.
'''
self._alerts = None
+ self._feed = None
self.geo = GeoDB()
self.state = state
self.scope = 'US'
+ self.cachetime = cachetime
if samecodes is None:
self.samecodes = None
elif isinstance(samecodes, str):
@@ -38,13 +40,23 @@ def __init__(self, state=None, samecodes=None, load=True):
def load_alerts(self):
'''
+ NOTE: use refresh() instead of this, if you are just needing to refresh the alerts list
Gets raw xml (cap) from the Alerts feed, throws it into the parser
and ends up with a list of alerts object, which it stores to self._alerts
'''
- cap = AlertsFeed(state=self.scope).raw_cap()
- parser = CapParser(cap, geo=self.geo)
+ self._feed = AlertsFeed(state=self.scope, maxage=self.cachetime)
+ parser = CapParser(self._feed.raw_cap(), geo=self.geo)
self._alerts = parser.get_alerts()
+ 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)
+ it'll only pull a new list if the cached copy is expired. (see cachetime)
+ '''
+ if force is True:
+ self._feed.refresh()
+ self._alerts = CapParser(self._feed.raw_cap(), geo=self.geo).get_alerts()
+
@property
def alerts(self):
if self.samecodes is not None:
@@ -72,7 +84,8 @@ def county_state_alerts(self, county, state):
return self.samecode_alerts(samecode)
def event_state_counties(self):
- '''Return an event type and it's state(s) and counties (consolidated)'''
+ '''DEPRECATED: this will be moved elsewhere or dropped in the near future, stop using it.
+ Return an event type and it's state(s) and counties (consolidated)'''
# FIXME: most of this logic should be moved to the alert instance and refactored
for alert in self._alerts:
locations = []

0 comments on commit 035904d

Please sign in to comment.