Code Documentation¶
Below you’ll find the documentation for the various classes and methods in WeatherAlerts.
Note
This page is dynamically generated from the documentation written within the code
WeatherAlerts¶
File Information¶
- Project Home:
- http://github.com/zebpalmer/WeatherAlerts
- Original Author:
- Zeb Palmer http://www.zebpalmer.com
- Documentation:
- http://weatheralerts.readthedocs.org
- License:
- MIT - full text included in LICENSE.txt
Code Documentation¶
-
class
WeatherAlerts
(state=None, samecodes=None, load=True, cachetime=3)¶ WeatherAlerts object that controls interaction with the NWS CAP alerts feed as well as various geo data sources. 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.
-
alerts
¶ 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.
-
county_state_alerts
(county, state)¶ Given a county and state, return alerts
-
event_state_counties
()¶ 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)
-
load_alerts
()¶ 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
-
refresh
(force=False)¶ 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)
-
samecode_alerts
(samecode)¶ Returns alerts for a ()single) SAME geocode. Only useful if you didn’t specify samecodes when the WeatherAlerts object was created.
-
class
GeoDB
¶ Interact with samecodes data will be adding additional data (zip code lookup) in the future.
-
getfeedscope
(geocodes)¶ Given multiple SAME codes, determine if they are all in one state. If so, it returns that state. Otherwise return ‘US’. This is used to determine which NWS feed needs to be parsed to get all alerts for the requested SAME codes
-
getstate
(geosame)¶ Given a SAME code, return the state that SAME code is in
-
location_lookup
(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
-
lookup_county_state
(samecode)¶ Given a samecode, return county, state
-
lookup_samecode
(local, state)¶ Given County, State return the SAME code for specified location. Return False if not found
-
-
class
SameCodes
¶ 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
-
reload
()¶ force refresh of Same Codes
-
samecodes
¶ public method to return the same codes list
-
-
class
AlertsFeed
(state='US', maxage=3)¶ Fetch the NWS CAP/XML Alerts feed for the US or a single state if requested if an instance of the GeoDB class has already been created, you can pass that as well to save some processing This will cache the feed (in local tempdir) for up to ‘maxage’ minutes
-
raw_cap
(refresh=False)¶ Raw xml(cap) of the the feed. If a valid cache is available 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
-
refresh
()¶ 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.
-
-
class
CapParser
(raw_cap, geo=None)¶ 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. I’ll be totally rewriting it shortly.
-
get_alerts
()¶ Public method that parses
-
-
build_target_areas
(entry)¶ Cleanup the raw target areas description string
-
class
Alert
(cap_dict)¶ Create an alert object with the cap dict created from cap xml parser.
This object won’t be pretty... it’s mostly a bunch of property methods to sanitize and muck around with the raw cap data. Using individual properties and methods instead of a special getattr so that we can more easily standardize the Alert API. This may be revisted in the future as the project becomes more stable.
-
areadesc
¶ A more generic area description
-
category
¶ Category of alert i.e. Met, Civil, etc
-
effective
¶ Effective timestamp of the alert (datetime object)
-
event
¶ alert event type
-
expiration
¶ Expiration of the alert (datetime object)
-
link
¶
-
msgtype
¶
-
published
¶ Published timestamp of the alert (datetime object)
-
samecodes
¶ samecodes for the alert area
-
severity
¶ Severity of alert i.e. minor, major, etc
-
summary
¶ Alert summary
-
title
¶ Alert title
-
updated
¶ Last update to the alert (datetime object)
-
urgency
¶ Alert urgency
-
zonecodes
¶ UCG codes for the alert area (these are sometimes referred to as county codes, but that’s not quite accurate)
-