| 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 subprocess |
|---|
| 45 | import os |
|---|
| 46 | |
|---|
| 47 | from AlertDevice import * |
|---|
| 48 | |
|---|
| 49 | class MediaAlertDevice(AlertDevice): |
|---|
| 50 | def __init__(self,mediaInfo,alerts,areas): |
|---|
| 51 | super(MediaAlertDevice,self).__init__(alerts,areas) |
|---|
| 52 | self.__mediaInfo = mediaInfo |
|---|
| 53 | |
|---|
| 54 | def display(self): |
|---|
| 55 | print self.__str__() |
|---|
| 56 | |
|---|
| 57 | def __str__(self): |
|---|
| 58 | str = "MediaAlertDevice\n" + \ |
|---|
| 59 | self.__mediaInfo.__str__() + \ |
|---|
| 60 | super(MediaAlertDevice,self).__str__() |
|---|
| 61 | return str |
|---|
| 62 | |
|---|
| 63 | def send(self,alert): |
|---|
| 64 | if(alert.type & ALERT): |
|---|
| 65 | self._play(self.__mediaInfo.alert) |
|---|
| 66 | if(alert.type & FORECAST): |
|---|
| 67 | self._play(self.__mediaInfo.forecast) |
|---|
| 68 | if(alert.type & STATEMENT): |
|---|
| 69 | self._play(self.__mediaInfo.statement) |
|---|
| 70 | if(alert.type & ADVISORY): |
|---|
| 71 | self._play(self.__mediaInfo.advisory) |
|---|
| 72 | if(alert.type & WATCH): |
|---|
| 73 | self._play(self.__mediaInfo.watch) |
|---|
| 74 | if(alert.type & WARNING): |
|---|
| 75 | self._play(self.__mediaInfo.warning) |
|---|
| 76 | |
|---|
| 77 | def _play(self,file): |
|---|
| 78 | try: |
|---|
| 79 | if(file): |
|---|
| 80 | subprocess.Popen([self.__mediaInfo.player,file]).wait() |
|---|
| 81 | else: |
|---|
| 82 | print "Can not play alert media: (%s) not found" % file |
|---|
| 83 | except os.error: |
|---|
| 84 | print "Problem trying to play: " + file |
|---|
| 85 | |
|---|
| 86 | class MediaAlertDeviceInfo(object): |
|---|
| 87 | def __init__(self): |
|---|
| 88 | self.__player = None |
|---|
| 89 | self.__forecast = None |
|---|
| 90 | self.__statement = None |
|---|
| 91 | self.__advisory = None |
|---|
| 92 | self.__watch = None |
|---|
| 93 | self.__warning = None |
|---|
| 94 | self.__alert = None |
|---|
| 95 | |
|---|
| 96 | def setPlayer(self,player): |
|---|
| 97 | self.__player = player |
|---|
| 98 | |
|---|
| 99 | def getPlayer(self): |
|---|
| 100 | return self.__player |
|---|
| 101 | |
|---|
| 102 | def setAlert(self,alert): |
|---|
| 103 | self.__alert = alert |
|---|
| 104 | |
|---|
| 105 | def getAlert(self): |
|---|
| 106 | return self.__alert |
|---|
| 107 | |
|---|
| 108 | def setForecast(self,forecast): |
|---|
| 109 | self.__forecast = forecast |
|---|
| 110 | |
|---|
| 111 | def getForecast(self): |
|---|
| 112 | return self.__forecast |
|---|
| 113 | |
|---|
| 114 | def setStatement(self,statement): |
|---|
| 115 | self.__statement = statement |
|---|
| 116 | |
|---|
| 117 | def getStatement(self): |
|---|
| 118 | return self.__statement |
|---|
| 119 | |
|---|
| 120 | def setAdvisory(self,advisory): |
|---|
| 121 | self.__advisory = advisory |
|---|
| 122 | |
|---|
| 123 | def getAdvisory(self): |
|---|
| 124 | return self.__advisory |
|---|
| 125 | |
|---|
| 126 | def setWatch(self,watch): |
|---|
| 127 | self.__watch = watch |
|---|
| 128 | |
|---|
| 129 | def getWatch(self): |
|---|
| 130 | return self.__watch |
|---|
| 131 | |
|---|
| 132 | def setWarning(self,warning): |
|---|
| 133 | self.__warning = warning |
|---|
| 134 | |
|---|
| 135 | def getWarning(self): |
|---|
| 136 | return self.__warning |
|---|
| 137 | |
|---|
| 138 | player = property(getPlayer,setPlayer,None) |
|---|
| 139 | alert = property(getAlert,setAlert,None) |
|---|
| 140 | forecast = property(getForecast,setForecast,None) |
|---|
| 141 | statement = property(getStatement,setStatement,None) |
|---|
| 142 | advisory = property(getAdvisory,setAdvisory,None) |
|---|
| 143 | watch = property(getWatch,setWatch,None) |
|---|
| 144 | warning = property(getWarning,setWarning,None) |
|---|
| 145 | |
|---|
| 146 | def display(self): |
|---|
| 147 | print self.__str__() |
|---|
| 148 | |
|---|
| 149 | def __str__(self): |
|---|
| 150 | str = "Media Info\n" |
|---|
| 151 | |
|---|
| 152 | if(self.player): |
|---|
| 153 | str += "\tPlayer: " + self.player + "\n" |
|---|
| 154 | |
|---|
| 155 | if(self.alert): |
|---|
| 156 | str += "\tAlert: " + self.alert + "\n" |
|---|
| 157 | |
|---|
| 158 | if(self.forecast): |
|---|
| 159 | str += "\tForecast: " + self.forecast + "\n" |
|---|
| 160 | |
|---|
| 161 | if(self.statement): |
|---|
| 162 | str += "\tStatement: " + self.statement + "\n" |
|---|
| 163 | |
|---|
| 164 | if(self.advisory): |
|---|
| 165 | str += "\tAdvisory: " + self.advisory + "\n" |
|---|
| 166 | |
|---|
| 167 | if(self.watch): |
|---|
| 168 | str += "\tWatch: " + self.watch + "\n" |
|---|
| 169 | |
|---|
| 170 | if(self.warning): |
|---|
| 171 | str += "\tWarning: " + self.warning + "\n" |
|---|
| 172 | |
|---|
| 173 | return str |
|---|