Changeset 102:b2f8756ebfeb

Show
Ignore:
Timestamp:
10/25/08 23:05:13 (3 years ago)
Author:
chris
Branch:
unix
Children:
103:53ed1f0943b8, 106:3b863d4d373e
Message:

add ability to send test alerts to all devices

Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • EmailAlertDevice.py

    r100 r102  
    7070                        str += "TextWidth: %i" % self.__textwidth 
    7171 
    72                 str += "To: " + self.to + "\n" + \ 
    73                                 self.__smtpInfo.__str__() + \ 
     72                str += self.__smtpInfo.__str__() + \ 
    7473                                super(EmailAlertDevice,self).__str__() 
    7574 
  • XmlWeather.py

    r100 r102  
    4343import urllib 
    4444import logging 
     45import sys 
    4546from xml.dom import minidom 
    4647 
     
    7475                        if(self.__simfetch): 
    7576                                self.log.info("Simulating fetch using examples directory") 
    76                                 self.dom = minidom.parse("examples/" + self.__state.lower() + ".cap") 
     77                                self.__dom = minidom.parse("examples/" + self.__state.lower() + ".cap") 
    7778                        else: 
    78                                 self.dom = minidom.parse(urllib.urlopen(self.__url)) 
    79                 except IOError: 
     79                                self.__dom = minidom.parse(urllib.urlopen(self.__url)) 
     80                except IOError,e: 
    8081                        # No net connection available, exit. 
    81                         self.log.error("Internet connection not available, exiting") 
     82                        self.log.error("Internet connection not available?, exiting: %s" % e) 
    8283                        sys.exit() 
    83  
    84                 self.__parse() 
    8584 
    8685        def __str__(self): 
     
    9998 
    10099        def __parse(self): 
    101                 for capXmlText in self.dom.getElementsByTagName(self.__tag_item): 
     100                for capXmlText in self.__dom.getElementsByTagName(self.__tag_item): 
    102101                        cap_item = CAP(capXmlText, self.__state) 
    103102                        #cap_item.display() 
  • ss.py

    r100 r102  
    4343from optparse import OptionParser 
    4444 
     45from TestAlert import TestAlert 
     46from WeatherAlert import WeatherAlert 
    4547from StormWeather import StormWeather 
    4648from StormConfig import StormConfig 
     
    7678                                        help="Override log configuration file", metavar="file_name", default=None) 
    7779 
     80        parser.add_option("-t", "--testpage",  
     81                                        action="store_true", dest="testpage", default=False, 
     82                                        help="Send a test alert to all configured devices") 
     83 
    7884 
    7985        (options, args) = parser.parse_args() 
     
    9298        #history.display() 
    9399 
    94         for state in conf.states: 
    95                 log.info("State: " + state) 
    96                 xw = StormWeather(state,history,options.simfetch,options.simalert) 
    97                 #xw.display() 
     100        if(not options.testpage): 
     101                for state in conf.states: 
     102                        log.info("State: " + state) 
     103                        xw = StormWeather(state,history,options.simfetch,options.simalert) 
     104                        #xw.display() 
     105                        for dev in conf.devices: 
     106                                if(dev.isStateWanted(state)): 
     107                                        xw.registerDevice(dev) 
     108                        xw.fetch() 
     109 
     110                history.save() 
     111        else: 
     112                log.info("Sending test page to all devices") 
     113                ta = TestAlert("examples/test-alert.cap") 
     114                ta.fetch() 
    98115                for dev in conf.devices: 
    99                         if(dev.isStateWanted(state)): 
    100                                 xw.registerDevice(dev) 
    101                 xw.fetch() 
    102  
    103         history.save() 
     116                        log.info("\tSending test alert to:\n%s" % dev.__str__()) 
     117                        dev.send(ta.weather_alert) 
    104118 
    105119