root/StormSiren/CapAlert.py

Revision 174:e1594aa49677, 3.5 KB (checked in by cfreeze@…, 3 years ago)

more cleanup with the output

  • 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 re
45import sys
46import datetime
47
48from WeatherTypes import WeatherTypes
49from XmlFetcher import XmlFetcher
50
51class 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)
Note: See TracBrowser for help on using the browser.