def get_cap_alert(region): url = 'http://www.weather.gov/alerts/%s.cap' % region try: xmldom = objectify.fromstring(HTTPRequest().open(url).read()) except IOError, e: conf.log('warning', 'RequestError: %s' % e) raise RequestError, e
def get_radar_report(station_id, radar_id='N0R'): data = {} url = URL % ("%s/%s_%s_0.gfw" % (radar_id.upper(), station_id.upper(), radar_id.upper())) try: data['world_file'] = map(lambda x: float(x.strip()), urlopen(url).readlines()) except IOError, e: conf.log('warning', 'RequestError: %s' % e) raise RequestError, e
def get_state_alert(state): """Returns alert data for a particular state. More information can be found here: http://www.weather.gov/alerts/ """ url = "http://www.weather.gov/alerts/%s.rss" % state.lower() try: xml_string = HTTPRequest().open(url).read() except IOError, e: conf.log('warning', 'RequestError: %s' % e) raise RequestError, e
def get_uv_index(zipcode='', city_name='', state_code=''): """Returns ultra violet index for a given city, state, or zipcode.""" if not zipcode and not (city_name and state_code): raise TypeError('Pass a zipcode or a city and state') url = 'http://oaspub.epa.gov/enviro/uv_search?'+ urlencode( {'zipcode': zipcode, 'city_name': city_name, 'state_code': state_code}) try: data = HTTPRequest().open(url).read() except IOError, e: conf.log('warning','RequestError: %s'%e) raise RequestError(e)
def get_zone_alert(zone): """Returns alert data for a particular County/Zone Code. The County/Zone codes can be found here: http://www.weather.gov/alerts/ This XML was formatted pretty badly (had extra spaces and newlines), so the .strip() was run on all string. """ url = "http://www.weather.gov/alerts/wwarssget.php?zone=%s" % zone try: xml_string = HTTPRequest().open(url).read() except IOError, e: conf.log('warning', 'RequestError: %s' % e) raise RequestError, e
def get_sun_report(**kwargs): """ Basic function for fetching sun report data """ vars = {'FFX' : 1, 'ZZZ' : 'END', 'xxy' : kwargs['year'], 'type' : kwargs['report_type']} if 'location' in kwargs: if kwargs['location'].state: vars['st'] = kwargs['location'].state.upper() if kwargs['location'].locality: vars['place'] = kwargs['location'].locality else: vars['st'] = kwargs.pop('st','') vars['place'] = kwargs.pop('place','') vars = urlencode(vars) try: lines = urllib2.urlopen(urllib2.Request(URL, vars)).readlines() except IOError, e: conf.log('warning','RequestError: %s'%e) raise RequestError, e
def get_radar_report(station_id, radar_id='N0R'): data = {} url = URL % ("%s/%s_%s_0.gfw" % (radar_id.upper(), station_id.upper(), radar_id.upper())) try: data['world_file'] = map(lambda x: float(x.strip()), urlopen(url).readlines()) except IOError, e: conf.log('warning', 'RequestError: %s' % e) raise RequestError, e url = URL % ("%s/%s/" % (radar_id.upper(), station_id.upper())) try: domreader = urlopen(url) except IOError, e: conf.log('warning', 'RequestError: %s' % e) raise RequestError, e data['file_list'] = [] r = re.compile(r'.*<img src="/icons/image2.gif".*<a href="(.*?)">.*') for x in domreader: search = r.search(x) if search: filename = search.groups()[0] date = filename.split('_')[1] time = filename.split('_')[2] data['file_list'].append({ 'image': url + search.groups()[0], 'datetime': datetime(int(date[:4]), int(date[4:6]),