root/StormSiren/WeatherTypes.py

Revision 177:e7e54a896aa3, 3.9 KB (checked in by cfreeze@…, 3 years ago)

clean up the execution device to actually be usable on the commandline

  • 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 string
45
46UNKNOWN   = 0
47WARNING   = 1
48WATCH     = 2
49ADVISORY  = 4
50STATEMENT = 8
51FORECAST  = 16
52ALERT     = 32
53
54class WeatherTypes(int):
55        def __new__(cls, val = UNKNOWN):
56                return int.__new__(cls,val)
57
58        def __init__(self, val = UNKNOWN):
59                int.__init__(self,val)
60
61        def __str__(self):
62                return self.toString()
63
64        def toString(val):
65                wtypes = []
66
67                if (val & WARNING):
68                        wtypes.append("Warning")
69                if (val & WATCH):
70                        wtypes.append("Watch")
71                if (val & ADVISORY):
72                        wtypes.append("Advisory")
73                if (val & STATEMENT):
74                        wtypes.append("Statement")
75                if (val & FORECAST):
76                        wtypes.append("Forecast")
77                if (val & ALERT):
78                        wtypes.append("Alert")
79
80                return string.join(wtypes,"|")
81        toString = staticmethod(toString)
82
83        def display(self):
84                print self.__str__()
85
86        def fromString(str):
87                lstr = str.lower()
88
89                if(lstr == "warning"):
90                        return WeatherTypes(WARNING)
91                elif(lstr == "watch"):
92                        return WeatherTypes(WATCH)
93                elif(lstr == "advisory"):
94                        return WeatherTypes(ADVISORY)
95                elif(lstr == "statement"):
96                        return WeatherTypes(STATEMENT)
97                elif(lstr == "forecast"):
98                        return WeatherTypes(FORECAST)
99                elif(lstr == "alert"):
100                        return WeatherTypes(ALERT)
101                else:
102                        return WeatherTypes(UNKNOWN)
103        fromString = staticmethod(fromString)
104
105        def isWarning(val):
106                if(val & WARNING):
107                        return True
108                else:
109                        return False
110        isWarning = staticmethod(isWarning)
111
112        def isWatch(val):
113                if(val & WATCH):
114                        return True
115                else:
116                        return False
117        isWatch = staticmethod(isWatch)
118
119        def isAdvisory(val):
120                if(val & ADVISORY):
121                        return True
122                else:
123                        return False
124        isAdvisory = staticmethod(isAdvisory)
125
126        def isStatement(val):
127                if(val & STATEMENT):
128                        return True
129                else:
130                        return False
131        isStatement = staticmethod(isStatement)
132
133        def isForecast(val):
134                if(val & FORECAST):
135                        return True
136                else:
137                        return False
138        isForecast = staticmethod(isForecast)
139
140        def isAlert(val):
141                if(val & ALERT):
142                        return True
143                else:
144                        return False
145        isAlert = staticmethod(isAlert)
Note: See TracBrowser for help on using the browser.