Changeset 102:b2f8756ebfeb
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r100
|
r102
|
|
| 70 | 70 | str += "TextWidth: %i" % self.__textwidth |
| 71 | 71 | |
| 72 | | str += "To: " + self.to + "\n" + \ |
| 73 | | self.__smtpInfo.__str__() + \ |
| | 72 | str += self.__smtpInfo.__str__() + \ |
| 74 | 73 | super(EmailAlertDevice,self).__str__() |
| 75 | 74 | |
-
|
r100
|
r102
|
|
| 43 | 43 | import urllib |
| 44 | 44 | import logging |
| | 45 | import sys |
| 45 | 46 | from xml.dom import minidom |
| 46 | 47 | |
| … |
… |
|
| 74 | 75 | if(self.__simfetch): |
| 75 | 76 | 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") |
| 77 | 78 | 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: |
| 80 | 81 | # 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) |
| 82 | 83 | sys.exit() |
| 83 | | |
| 84 | | self.__parse() |
| 85 | 84 | |
| 86 | 85 | def __str__(self): |
| … |
… |
|
| 99 | 98 | |
| 100 | 99 | def __parse(self): |
| 101 | | for capXmlText in self.dom.getElementsByTagName(self.__tag_item): |
| | 100 | for capXmlText in self.__dom.getElementsByTagName(self.__tag_item): |
| 102 | 101 | cap_item = CAP(capXmlText, self.__state) |
| 103 | 102 | #cap_item.display() |
-
|
r100
|
r102
|
|
| 43 | 43 | from optparse import OptionParser |
| 44 | 44 | |
| | 45 | from TestAlert import TestAlert |
| | 46 | from WeatherAlert import WeatherAlert |
| 45 | 47 | from StormWeather import StormWeather |
| 46 | 48 | from StormConfig import StormConfig |
| … |
… |
|
| 76 | 78 | help="Override log configuration file", metavar="file_name", default=None) |
| 77 | 79 | |
| | 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 | |
| 78 | 84 | |
| 79 | 85 | (options, args) = parser.parse_args() |
| … |
… |
|
| 92 | 98 | #history.display() |
| 93 | 99 | |
| 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() |
| 98 | 115 | 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) |
| 104 | 118 | |
| 105 | 119 | |