In [1]:
    
from owslib.csw import CatalogueServiceWeb
from owslib import fes
    
In [2]:
    
# simple query for text only
val='gamssa'
filter_list = [fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*%s*' % val),
                        escapeChar='\\',wildCard='*',singleChar='?')]
    
In [3]:
    
def service_urls(records,service_string='urn:x-esri:specification:ServiceType:odp:url'):
    """
    Get all URLs matching a specific ServiceType 
 
    Unfortunately these seem to differ between different CSW-ISO services.
    For example, OpenDAP is specified:
    NODC geoportal: 'urn:x-esri:specification:ServiceType:OPeNDAP'
    NGDC geoportal: 'urn:x-esri:specification:ServiceType:odp:url'
    """
    urls=[]
    for key,rec in records.iteritems():
        #create a generator object, and iterate through it until the match is found
        #if not found, gets the default value (here "none")
        url = next((d['url'] for d in rec.references if d['scheme'] == service_string), None)
        if url is not None:
            urls.append(url)
    return urls
    
In [4]:
    
endpoint = 'http://data.nodc.noaa.gov/geoportal/csw'   
csw = CatalogueServiceWeb(endpoint,timeout=60)
print csw.version
    
    
In [5]:
    
for oper in csw.operations:
    if oper.name == 'GetRecords':
        print '\nISO Queryables:\n',oper.constraints['SupportedISOQueryables']['values']
    
    
In [6]:
    
csw.getrecords2(constraints=filter_list,maxrecords=10000,esn='full')
len(csw.records.keys())
    
    Out[6]:
In [7]:
    
choice=random.choice(list(csw.records.keys()))
print choice
csw.records[choice].references
    
    
    Out[7]:
In [8]:
    
#find all WMS URLs
wms_urls = service_urls(csw.records,service_string='urn:x-esri:specification:ServiceType:WMS')
len(wms_urls)
    
    Out[8]:
In [9]:
    
endpoint = 'http://www.nodc.noaa.gov/geoportal/csw' 
csw = CatalogueServiceWeb(endpoint,timeout=60)
csw.version
    
    Out[9]:
In [10]:
    
for oper in csw.operations:
    if oper.name == 'GetRecords':
        print '\nISO Queryables:\n',oper.constraints['SupportedISOQueryables']['values']
    
    
In [11]:
    
csw.getrecords2(constraints=filter_list,maxrecords=10000,esn='full')
len(csw.records.keys())
    
    Out[11]:
In [12]:
    
choice=random.choice(list(csw.records.keys()))
print choice
csw.records[choice].references
    
    
    Out[12]:
In [13]:
    
#find all WMS URLs
wms_urls = service_urls(csw.records,service_string='urn:x-esri:specification:ServiceType:WMS')
len(wms_urls)
    
    Out[13]:
In [14]:
    
endpoint = 'http://catalog.data.gov/csw' #  catalog.data.gov CSW
csw = CatalogueServiceWeb(endpoint,timeout=60)
csw.version
    
    Out[14]:
In [15]:
    
for oper in csw.operations:
    if oper.name == 'GetRecords':
        print '\nISO Queryables:\n',oper.constraints['SupportedISOQueryables']['values']
    
    
In [16]:
    
csw.getrecords2(constraints=filter_list,maxrecords=10000,esn='full')
len(csw.records.keys())
    
    Out[16]:
In [17]:
    
choice=random.choice(list(csw.records.keys()))
print choice
csw.records[choice].references
    
    
    Out[17]:
From the above, we can see that because the 'scheme' is 'None' on all the references, we can't extract the different service types, like OPeNDAP, WCS, etc.
In [18]:
    
#find all WMS URLs
wms_urls = service_urls(csw.records,service_string='urn:x-esri:specification:ServiceType:WMS')
len(wms_urls)
    
    Out[18]:
In [19]:
    
endpoint = 'http://catalog.data.gov/csw-all'
csw = CatalogueServiceWeb(endpoint,timeout=60)
print csw.version
    
    
In [20]:
    
for oper in csw.operations:
    if oper.name == 'GetRecords':
        print '\nISO Queryables:\n',oper.constraints['SupportedISOQueryables']['values']
    
    
In [21]:
    
csw.getrecords2(constraints=filter_list,maxrecords=10000,esn='full')
len(csw.records.keys())
    
    Out[21]:
In [22]:
    
choice=random.choice(list(csw.records.keys()))
print choice
csw.records[choice].references
    
    
    Out[22]:
In [23]:
    
#find all WMS URLs
wms_urls = service_urls(csw.records,service_string='urn:x-esri:specification:ServiceType:WMS')
len(wms_urls)
    
    Out[23]:
In [23]: