def test_get_clip_dates(): sdate, edate = datetime(2000, 01, 01), datetime(2000, 01, 31) params = {'from-date': sdate.strftime('%Y/%m/%d'), 'to-date': edate.strftime('%Y/%m/%d')} req = Request.blank('?' + urlencode(params)) rv = get_clip_dates(req.environ) # If cliptodate is not set, then get_clip_dates ignores the dates assert rv == (None, None) params['cliptodate'] = 'True' req = Request.blank('?' + urlencode(params)) rv = get_clip_dates(req.environ) assert rv == (sdate, edate) # Does it work with just one of the two dates? del params['from-date'] req = Request.blank('?' + urlencode(params)) rv = get_clip_dates(req.environ) assert rv == (None, edate)
def __call__(self, environ, start_response): req = Request(environ) form = req.params filters = validate_vars(environ) sdate, edate = get_clip_dates(environ) with self.session_scope_factory() as sesh: stns = [stn[0] for stn in get_stn_list(sesh, filters, cng.station_id)] rv = length_of_return_dataset(sesh, stns, sdate, edate) obs_count = int(rv[0] if rv[0] else 0) rv = length_of_return_climo(sesh, stns) climo_count = int(rv[0] if rv[0] else 0) status = '200 OK' response_headers = [('Content-type', 'application/json; charset=utf-8')] start_response(status, response_headers) return json.dumps({'record_length': obs_count, 'climo_length': climo_count})
def __call__(self, environ, start_response): '''Fire off pydap requests and return an iterable (from :func:`ziperator`)''' req = Request(environ) form = req.params climo = True if 'download-climatology' in form else False filters = validate_vars(environ) stns = get_stn_list(self.session, filters) ext = get_extension(environ) if not ext: return HTTPBadRequest("Requested extension not supported")(environ, start_response) status = '200 OK' response_headers = [('Content-type','application/zip'), ('Content-Disposition', 'filename="pcds_data.zip"')] start_response(status, response_headers) environ['pydap.handlers.pcic.dsn'] = self.dsn responders = chain(get_all_metadata_index_responders(self.session, stns, climo), get_pcds_responders(self.dsn, stns, ext, get_clip_dates(environ), environ) ) return ziperator(responders)
def __call__(self, environ, start_response): req = Request(environ) form = req.params filters = validate_vars(environ) sdate, edate = get_clip_dates(environ) sesh = environ.get('sesh', None) @contextmanager def dummy_context(): yield sesh with self.session_scope_factory() if not sesh \ else dummy_context() as sesh: counts = get_counts(sesh, filters, sdate, edate) status = '200 OK' response_headers = [('Content-type', 'application/json; charset=utf-8')] start_response(status, response_headers) return json.dumps(counts)