root/StormSiren/MediaAlertDevice.py

Revision 122:014251f26abf, 4.8 KB (checked in by chris, 3 years ago)

start moving files around to make it more package friendly

  • Property exe set to *
Line 
1#!/usr/bin/env python
2
3"""
4StormSiren
5Copyright (C) 2008  Chris Freeze <cfreeze/cfreeze_com\>
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions
9are met:
10
111. Redistributions of source code must retain the above copyright
12   notice, this list of conditions and the following disclaimer.
132. 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
17THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27"""
28
29"""
30This is StormSiren a program inspired by the StormSiren application
31written by Roy McManus <slorf/users_sourceforge_net>.  Much like the
32original StormSiren written by Roy McManus <slorf/users_sourceforge_net>,
33this program is a simple script capable of scanning and providing
34notifications of weather bulletins issued by the National
35Weather Service.  StormSiren supports a wide range of paging devices
36and filtering of alert types per alert device.  While inspired by
37StormSiren, StormSiren is a complete rewrite that is capable of using
38the new CAP/XML feeds provided at http://www.weather.gov/alerts/.
39
40For more information there is see the README.TXT file located in the root
41of this directory.
42"""
43
44import subprocess
45import os
46
47from AlertDevice import *
48
49class 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
86class 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
Note: See TracBrowser for help on using the browser.