Changeset 154:af3c0e9a711e

Show
Ignore:
Timestamp:
11/15/08 16:39:39 (3 years ago)
Author:
chris
Branch:
unix
Message:

break fetching out to separate class

Location:
StormSiren
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • StormSiren/XmlWeather.py

    r143 r154  
    4242""" 
    4343 
    44 import urllib2 
    4544import logging 
    46 import sys 
    47 from xml.dom import minidom 
    4845 
    4946from WeatherTypes import * 
     47from XmlFetcher import * 
    5048from CAP import CAP 
    5149 
     
    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' 
     56                self.__baseurl    = 'http://www.weather.gov/wwarss-tst/' 
     57                #self.__url        = self.__baseurl + self.__state.lower() + ".php?x=0"  
     58                self.__url        = "http://www.weather.gov/alerts/" + self.__state.lower() + ".cap"  
     59                #self.__tag_item   = 'cap:info' 
     60                self.__tag_item   = 'entry' 
    6261                self.__history    = history 
    6362                self.__simfetch   = simfetch 
    6463                self.__proxy      = proxy 
     64                self.__atoms      = XmlFetcher(self.__url, self.__simfetch, self.__proxy) 
    6565                self.log = logging.getLogger("XmlWeather") 
    6666 
     
    7373 
    7474        def __fetch(self): 
    75                 self.log.info("Fetching: " + self.__url) 
    76                 try: 
    77                         if(self.__simfetch): 
    78                                 self.log.info("Simulating fetch using examples directory") 
    79                                 self.__dom = minidom.parse("examples/" + self.__state.lower() + ".cap") 
    80                         else: 
    81                                 if(self.__proxy): 
    82                                         self.log.info("Using proxy: %s" % self.__proxy) 
    83                                         proxy_support = urllib2.ProxyHandler({"http" : self.__proxy}) 
    84                                         opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) 
    85                                         urllib2.install_opener(opener) 
    86                                 self.__dom = minidom.parse(urllib2.urlopen(self.__url)) 
    87                 except IOError,e: 
    88                         # No net connection available, exit. 
    89                         self.log.error("Internet connection not available?, exiting: %s" % e) 
    90                         sys.exit() 
     75                self.__dom = self.__atoms.fetch() 
    9176 
    9277        def __str__(self): 
     
    9479                                "State: " + self.__state + "\n" + \ 
    9580                                "URL: " + self.__url + "\n" 
    96  
    97                 if(self.__simfetch): 
    98                         str += "Sim Fetch: yes\n" 
    99                 else: 
    100                         str += "Sim Fetch: no\n" 
    10181                return str 
    10282