Changeset 154:af3c0e9a711e
- Timestamp:
- 11/15/08 16:39:39 (3 years ago)
- Author:
- chris
- Branch:
- unix
- Message:
-
break fetching out to separate class
- Location:
- StormSiren
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r143
|
r154
|
|
| 42 | 42 | """ |
| 43 | 43 | |
| 44 | | import urllib2 |
| 45 | 44 | import logging |
| 46 | | import sys |
| 47 | | from xml.dom import minidom |
| 48 | 45 | |
| 49 | 46 | from WeatherTypes import * |
| | 47 | from XmlFetcher import * |
| 50 | 48 | from CAP import CAP |
| 51 | 49 | |
| … |
… |
|
| 56 | 54 | self.__state = state |
| 57 | 55 | 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' |
| 62 | 61 | self.__history = history |
| 63 | 62 | self.__simfetch = simfetch |
| 64 | 63 | self.__proxy = proxy |
| | 64 | self.__atoms = XmlFetcher(self.__url, self.__simfetch, self.__proxy) |
| 65 | 65 | self.log = logging.getLogger("XmlWeather") |
| 66 | 66 | |
| … |
… |
|
| 73 | 73 | |
| 74 | 74 | 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() |
| 91 | 76 | |
| 92 | 77 | def __str__(self): |
| … |
… |
|
| 94 | 79 | "State: " + self.__state + "\n" + \ |
| 95 | 80 | "URL: " + self.__url + "\n" |
| 96 | | |
| 97 | | if(self.__simfetch): |
| 98 | | str += "Sim Fetch: yes\n" |
| 99 | | else: |
| 100 | | str += "Sim Fetch: no\n" |
| 101 | 81 | return str |
| 102 | 82 | |