from owslib.csw import CatalogueServiceWeb
from owslib import fes
from pprint import pprint
#endpoint = 'https://gamone.whoi.edu/csw'
endpoint = 'https://data.ioos.us/csw'
csw = CatalogueServiceWeb(endpoint,timeout=60)
print(csw.version)
2.0.2
def get_csw_records(csw, filter_list, pagesize=10, maxrecords=1000):
"""Iterate `maxrecords`/`pagesize` times until the requested value in
`maxrecords` is reached.
"""
from owslib.fes import SortBy, SortProperty
# Iterate over sorted results.
sortby = SortBy([SortProperty('dc:title', 'ASC')])
csw_records = {}
startposition = 0
nextrecord = getattr(csw, 'results', 1)
while nextrecord != 0:
csw.getrecords2(constraints=filter_list, startposition=startposition,
maxrecords=pagesize, sortby=sortby)
csw_records.update(csw.records)
if csw.results['nextrecord'] == 0:
break
startposition += pagesize + 1 # Last one is included.
if startposition >= maxrecords:
break
csw.records.update(csw_records)
val = 'sea_surface_height'
filter1 = fes.PropertyIsEqualTo(propertyname='apiso:AnyText',literal=val)
val = 'bedford'
filter2 = fes.PropertyIsEqualTo(propertyname='apiso:AnyText',literal=val)
#filter2 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
# escapeChar='\\',wildCard='*',singleChar='?')
filter_list = [fes.And([filter1, filter2])]
get_csw_records(csw, filter_list, maxrecords=1000)
#csw.getrecords2(constraints=filter_list, maxrecords=1000)
print(len(csw.records.keys()))
for rec in list(csw.records.keys()):
print('title:'+csw.records[rec].title)
print('identifier:'+csw.records[rec].identifier)
print('modified:'+csw.records[rec].modified)
print(' ')
3 title:BIO WW III Latest Forecasts/EastCoast.nc identifier:ca.gc.bio:WW3/Forecasts/EastCoast.nc modified:2018-03-04 title:BIO WW III Latest Forecasts/GulfOfMaine.nc identifier:ca.gc.bio:WW3/Forecasts/GulfOfMaine.nc modified:2018-03-04 title:BIO WW III Latest Forecasts/NorthAtlantic.nc identifier:ca.gc.bio:WW3/Forecasts/NorthAtlantic.nc modified:2018-03-04