| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | StormSiren |
|---|
| 5 | Copyright (C) 2008 Chris Freeze <cfreeze/cfreeze_com\> |
|---|
| 6 | |
|---|
| 7 | Redistribution and use in source and binary forms, with or without |
|---|
| 8 | modification, are permitted provided that the following conditions |
|---|
| 9 | are met: |
|---|
| 10 | |
|---|
| 11 | 1. Redistributions of source code must retain the above copyright |
|---|
| 12 | notice, this list of conditions and the following disclaimer. |
|---|
| 13 | 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 14 | notice, this list of conditions and the following disclaimer in the |
|---|
| 15 | documentation and/or other materials provided with the distribution. |
|---|
| 16 | |
|---|
| 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 | """ |
|---|
| 28 | |
|---|
| 29 | """ |
|---|
| 30 | This is StormSiren a program inspired by the StormSiren application |
|---|
| 31 | written by Roy McManus <slorf/users_sourceforge_net>. Much like the |
|---|
| 32 | original StormSiren written by Roy McManus <slorf/users_sourceforge_net>, |
|---|
| 33 | this program is a simple script capable of scanning and providing |
|---|
| 34 | notifications of weather bulletins issued by the National |
|---|
| 35 | Weather Service. StormSiren supports a wide range of paging devices |
|---|
| 36 | and filtering of alert types per alert device. While inspired by |
|---|
| 37 | StormSiren, StormSiren is a complete rewrite that is capable of using |
|---|
| 38 | the new CAP/XML feeds provided at http://www.weather.gov/alerts/. |
|---|
| 39 | |
|---|
| 40 | For more information there is see the README.TXT file located in the root |
|---|
| 41 | of this directory. |
|---|
| 42 | """ |
|---|
| 43 | |
|---|
| 44 | import re |
|---|
| 45 | import sys |
|---|
| 46 | import datetime |
|---|
| 47 | |
|---|
| 48 | from WeatherTypes import WeatherTypes |
|---|
| 49 | from XmlFetcher import XmlFetcher |
|---|
| 50 | |
|---|
| 51 | class CapAlert(object): |
|---|
| 52 | def __init__(self,url,simfetch,proxy): |
|---|
| 53 | self.__url = url |
|---|
| 54 | self.__simfetch = simfetch |
|---|
| 55 | self.__proxy = proxy |
|---|
| 56 | self.__tag_headline = 'headline' |
|---|
| 57 | self.__headline = '' |
|---|
| 58 | self.__tag_description = 'description' |
|---|
| 59 | self.__headline = '' |
|---|
| 60 | self.__xmlfetcher = XmlFetcher(self.__url, self.__simfetch, self.__proxy) |
|---|
| 61 | self.__dom = None |
|---|
| 62 | |
|---|
| 63 | self.fetch() |
|---|
| 64 | |
|---|
| 65 | def fetch(self): |
|---|
| 66 | self.__fetch() |
|---|
| 67 | self.__parse() |
|---|
| 68 | |
|---|
| 69 | def __fetch(self): |
|---|
| 70 | self.__dom = self.__xmlfetcher.fetch() |
|---|
| 71 | |
|---|
| 72 | def __getfield(self,xml,tag): |
|---|
| 73 | val = xml.getElementsByTagName(tag) |
|---|
| 74 | |
|---|
| 75 | if(val): |
|---|
| 76 | return val[0].firstChild.data |
|---|
| 77 | else: |
|---|
| 78 | return "" |
|---|
| 79 | |
|---|
| 80 | def __trim(self,str): |
|---|
| 81 | if(str): |
|---|
| 82 | str = str.strip() |
|---|
| 83 | str = str.replace("\n","") |
|---|
| 84 | return str |
|---|
| 85 | |
|---|
| 86 | def __parse(self): |
|---|
| 87 | self.__headline = self.__trim(self.__getfield(self.__dom,self.__tag_headline)) |
|---|
| 88 | self.__description = self.__getfield(self.__dom,self.__tag_description) |
|---|
| 89 | |
|---|
| 90 | def __str__(self): |
|---|
| 91 | str = "Headline: " + self.headline + "\n" + \ |
|---|
| 92 | "\tURL: " + self.__url + "\n" |
|---|
| 93 | return str |
|---|
| 94 | |
|---|
| 95 | def display(self): |
|---|
| 96 | print self.__str__() |
|---|
| 97 | |
|---|
| 98 | def displayFull(self): |
|---|
| 99 | self.display() |
|---|
| 100 | print "\tDescription: " + self.description + "\n" |
|---|
| 101 | |
|---|
| 102 | def getDescription(self): |
|---|
| 103 | return self.__description |
|---|
| 104 | |
|---|
| 105 | def getHeadline(self): |
|---|
| 106 | return self.__headline |
|---|
| 107 | |
|---|
| 108 | description = property(getDescription,None,None) |
|---|
| 109 | headline = property(getHeadline,None,None) |
|---|