#!/usr/bin/env python # coding: utf-8 # # from owslib.csw import CatalogueServiceWeb # from owslib import fes # from pprint import pprint # In[2]: #endpoint = 'http://geoport.whoi.edu/csw' #endpoint = 'http://data.nodc.noaa.gov/geoportal/csw' #endpoint = 'https://data.ioos.us/csw' #endpoint = 'https://dev-catalog.ioos.us/csw' endpoint = 'https://gamone.whoi.edu/csw' csw = CatalogueServiceWeb(endpoint,timeout=60) print(csw.version) # In[3]: 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) # In[4]: val = 'CMG_Portal' filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val), escapeChar='\\',wildCard='*',singleChar='?') val = 'Barnegat' 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) pprint(csw.records[rec].references[2]) print(' ') # In[5]: val = 'CMG_Portal' filter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val), escapeChar='\\',wildCard='*',singleChar='?') filter_list = [filter1] 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) pprint(csw.records[rec].references[2]) print(' ') # ### csw.get_operation_by_name('GetRecords').constraints # In[ ]: # In[ ]: # In[ ]: # # try: # csw.get_operation_by_name('GetDomain') # csw.getdomain('apiso:ServiceType', 'property') # print(csw.results['values']) # except: # print('GetDomain not supported')