| 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 string |
|---|
| 45 | |
|---|
| 46 | UNKNOWN = 0 |
|---|
| 47 | WARNING = 1 |
|---|
| 48 | WATCH = 2 |
|---|
| 49 | ADVISORY = 4 |
|---|
| 50 | STATEMENT = 8 |
|---|
| 51 | FORECAST = 16 |
|---|
| 52 | ALERT = 32 |
|---|
| 53 | |
|---|
| 54 | class 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) |
|---|