In [ ]:
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

In [ ]:
#First lets import the libraries we require
from pprint import pprint
import podaac.podaac as podaac
import podaac.podaac_utils as utils

In [ ]:
#Then we can create instances of the classes we will use
p = podaac.Podaac()
u = utils.PodaacUtils()

In [ ]:
#Print a list of CYGNSS dataset id's
print('\nHeres list_all_available_granule_search_dataset_ids()')
result = u.list_all_available_granule_search_dataset_ids()
dsetId = [i for i in result if 'CYG' in i]
print(dsetId)

In [ ]:
#Print a list of CYGNSS dataset short names
print('\nHeres list_all_available_granule_search_dataset_short_names()')
result = u.list_all_available_granule_search_dataset_short_names()
dsetShortName = [i for i in result if 'CYG' in i]
print(dsetShortName)

In [ ]:
# Some dataset metadata in GCMD response format
print('\nHeres p.dataset_metadata()')
print(p.dataset_metadata(dataset_id=dsetId[0], format='gcmd'))

In [ ]:
#Perform a search on dataset
#NOTE: dataset_id=dsetID pulled up nothing, had to use short_name=
print('\nHeres p.dataset_search()')
result = p.dataset_search(short_name=dsetShortName[0])

#Cache the dataset landing page URL
searchStr = 'http://podaac.jpl.nasa.gov/dataset/'
dataset_landing_page = [ str(i) for i in result.strip().split() if searchStr in i ][0]

print(result)

In [ ]:
#Print total number of GYGNSS granules
print('\nHeres total results using p.granule_search()')
maxResultsPerPage = '400'
result = p.granule_search(dataset_id=dsetId[0],items_per_page=maxResultsPerPage)
print(result)
searchStr = 'totalResults'
numResultsStr = [ str(i) for i in result.strip().split() if searchStr in i ]
print(numResultsStr)

In [ ]:
#print('\nHeres the length of file listing: '+str(len(fileStrL))+'\n')
searchStr = '<title>cyg'
fileStrL = [ str(i) for i in result.strip().split() if searchStr in i ]
podaacL3 = [ i.replace('<title>','').replace('</title>','') for i in fileStrL ]
pprint(podaacL3)

In [ ]:
#Using Elsevier's Scopus Search, lets see if we can 
#retreieve any information from the above dataset landing page
url = 'https://api.elsevier.com/content/search/scopus?query=ALL:' + dataset_landing_page + '&APIKey=715b412c00f0b95e918a3e7abe6e6ee4'
import requests
try:
    metadata = requests.get(url)
    status_codes = [404, 400, 503, 408]
    if metadata.status_code in status_codes:
        metadata.raise_for_status()
except requests.exceptions.HTTPError as error:
    print(error)
    raise

pprint(metadata.text)

In [ ]:
#Again, using Elsevier's Scopus Search, lets see other CYGNSS resource we can retreive.
url = 'https://api.elsevier.com/content/search/scopus?query=ALL:cygnss&APIKey=715b412c00f0b95e918a3e7abe6e6ee4'
import requests
try:
    metadata = requests.get(url)
    status_codes = [404, 400, 503, 408]
    if metadata.status_code in status_codes:
        metadata.raise_for_status()
except requests.exceptions.HTTPError as error:
    print(error)
    raise

pprint(metadata.text)