Show
Ignore:
Timestamp:
11/29/08 00:48:18 (3 years ago)
Author:
cfreeze@…
Branch:
default
Parents:
189:8190540dae37 (diff), 185:c20e85874308 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

correct merge problems that are showing up from bad branching

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • StormSiren/XmlWeather.py

    r184 r190  
    4242""" 
    4343 
    44 import urllib 
    4544import logging 
    46 import sys 
    47 from xml.dom import minidom 
    4845 
    4946from WeatherTypes import * 
    50 from CAP import CAP 
     47from XmlFetcher import * 
     48from WeatherAlert import WeatherAlert 
    5149 
    5250class XmlWeather(object): 
    53         def __init__(self, state, history, simfetch = False): 
     51        def __init__(self, state, simfetch = False, proxy = None): 
    5452                super(XmlWeather,self).__init__() 
    5553                self.__data       = '' 
    5654                self.__state      = state 
    5755                self.__dom        = [] 
    58                 self.__baseurl    = 'http://www.weather.gov/alerts/' 
    59                 self.__namespace  = 'http://purl.org/dc/elements/1.1/' 
    60                 self.__url        = self.__baseurl + self.__state.lower() + ".cap"  
    61                 self.__tag_item   = 'cap:info' 
    62                 self.__history    = history 
     56                self.__baseurl    = 'http://www.weather.gov/wwarss-tst/' 
     57                self.__url        = self.__baseurl + self.__state.lower() + ".php?x=0"  
     58                self.__tag_item   = 'entry' 
    6359                self.__simfetch   = simfetch 
    64                 self.log = logging.getLogger("XmlWeather") 
     60                self.__proxy      = proxy 
     61                self.__atoms      = XmlFetcher(self.__url, self.__simfetch, self.__proxy) 
     62                self.log          = logging.getLogger("XmlWeather") 
    6563 
    6664                self.log.setLevel(logging.DEBUG) 
     
    7472 
    7573        def __fetch(self): 
    76                 self.log.info("Fetching: " + self.__url) 
    77                 try: 
    78                         if(self.__simfetch): 
    79                                 self.log.info("Simulating fetch using examples directory") 
    80                                 self.__dom = minidom.parse("examples/" + self.__state.lower() + ".cap") 
    81                         else: 
    82                                 self.__dom = minidom.parse(urllib.urlopen(self.__url)) 
    83                 except IOError,e: 
    84                         # No net connection available, exit. 
    85                         self.log.error("Internet connection not available?, exiting: %s" % e) 
    86                         sys.exit() 
     74                self.__dom = self.__atoms.fetch() 
    8775 
    8876        def __str__(self): 
    8977                str  = "XmlWeather:\n" + \ 
     78                                "SimFetch: " + self.__simfetch + "\n" + \ 
     79                                "Proxy: " + self.__proxy + "\n" + \ 
    9080                                "State: " + self.__state + "\n" + \ 
    9181                                "URL: " + self.__url + "\n" 
    92  
    93                 if(self.__simfetch): 
    94                         str += "Sim Fetch: yes\n" 
    95                 else: 
    96                         str += "Sim Fetch: no\n" 
    9782                return str 
    9883 
     
    10287        def __parse(self): 
    10388                for capXmlText in self.__dom.getElementsByTagName(self.__tag_item): 
    104                         cap_item = CAP(capXmlText, self.__state) 
    105                         #cap_item.display() 
    106                         if(not self.__history.exists(cap_item.id)): 
    107                                 alerted = self.handleAlert(cap_item) 
    108                                 if(alerted): 
    109                                         self.__history.add(cap_item.id) 
    110                         else: 
    111                                 self.log.debug("Ignoring %s: Already alerted on" % cap_item.id) 
     89                        self.handleAtom(WeatherAlert(capXmlText, self.__state)) 
    11290 
     91        def getSimFetch(self): 
     92                return self.__simfetch 
    11393 
    114         def handleAlert(self,cap_item): 
    115                 self.log.debug("handleAlert(%s) - %s/%s" % (cap_item.id, cap_item.county, cap_item.state)) 
    116                 return True 
     94        simfetch = property(getSimFetch,None,None) 
     95 
     96        def getProxy(self): 
     97                return self.__proxy 
     98 
     99        proxy = property(getProxy,None,None)