Exemple #1
0
    def get_info_url(self, dataset_id, response='csv'):
        """Compose the info URL for the `server_url` endpoint.

        Args:
            dataset_id (str): a dataset unique id.
            response (str): default is a Comma Separated Value ('csv').
                See ERDDAP docs for all the options,

                - tabledap: http://coastwatch.pfeg.noaa.gov/erddap/tabledap/documentation.html
                - griddap: http://coastwatch.pfeg.noaa.gov/erddap/griddap/documentation.html
        Returns:
            info_url (str): the info URL for the `response` chosen.

        """
        response = _clean_response(response)
        base = '{server_url}/info/{dataset_id}/index.{response}'.format
        info_options = {
            'server_url': self.server_url,
            'dataset_id': dataset_id,
            'response': response
        }
        info_url = base(**info_options)
        _check_url_response(info_url)
        return info_url
def test__clean_response():
    ret0 = _clean_response('html')
    ret1 = _clean_response('.html')
    assert ret0 == ret1
Exemple #3
0
def test__clean_response():
    """Test if users can pass responses with or without the '.'."""
    assert _clean_response("html") == _clean_response(".html")
Exemple #4
0
    def get_search_url(self,
                       response='csv',
                       search_for=None,
                       items_per_page=1000,
                       page=1,
                       **kwargs):
        """Compose the search URL for the `server_url` endpoint provided.

        Args:
            search_for (str): "Google-like" search of the datasets' metadata.

                - Type the words you want to search for, with spaces between the words.
                  ERDDAP will search for the words separately, not as a phrase.
                - To search for a phrase, put double quotes around the phrase
                  (for example, `"wind speed"`).
                - To exclude datasets with a specific word, use `-excludedWord`.
                - To exclude datasets with a specific phrase, use `-"excluded phrase"`
                - Searches are not case-sensitive.
                - To find just grid or just table datasets, include `protocol=griddap`
                  or `protocol=tabledap` in your search.
                - You can search for any part of a word. For example,
                  searching for `spee` will find datasets with `speed` and datasets with
                  `WindSpeed`
                - The last word in a phrase may be a partial word. For example,
                  to find datasets from a specific website (usually the start of the datasetID),
                  include (for example) `"datasetID=erd"` in your search.

            response (str): default is a Comma Separated Value ('csv').
                See ERDDAP docs for all the options,

                - tabledap: http://coastwatch.pfeg.noaa.gov/erddap/tabledap/documentation.html
                - griddap: http://coastwatch.pfeg.noaa.gov/erddap/griddap/documentation.html

            items_per_page (int): how many items per page in the return,
                default is 1000.
            page (int): which page to display, defatul is the first page (1).
            kwargs (dict): extra search constraints based on metadata and/or coordinates ke/value.
                metadata: `cdm_data_type`, `institution`, `ioos_category`,
                `keywords`, `long_name`, `standard_name`, and `variableName`.
                coordinates: `minLon`, `maxLon`, `minLat`, `maxLat`, `minTime`, and `maxTime`.
        Returns:
            search_url (str): the search URL for the `response` chosen.

        """
        base = ('{server_url}/search/advanced.{response}'
                '?page={page}'
                '&itemsPerPage={itemsPerPage}'
                '&protocol={protocol}'
                '&cdm_data_type={cdm_data_type}'
                '&institution={institution}'
                '&ioos_category={ioos_category}'
                '&keywords={keywords}'
                '&long_name={long_name}'
                '&standard_name={standard_name}'
                '&variableName={variableName}'
                '&minLon={minLon}'
                '&maxLon={maxLon}'
                '&minLat={minLat}'
                '&maxLat={maxLat}'
                '&minTime={minTime}'
                '&maxTime={maxTime}')
        if search_for:
            search_for = quote_plus(search_for)
            base += '&searchFor={searchFor}'

        # Convert dates from datetime to `seconds since 1970-01-01T00:00:00Z`.
        min_time = kwargs.pop('min_time', None)
        max_time = kwargs.pop('max_time', None)
        if min_time:
            kwargs.update({'min_time': parse_dates(min_time)})
        if max_time:
            kwargs.update({'max_time': parse_dates(max_time)})

        default = '(ANY)'
        response = _clean_response(response)
        search_options = {
            'server_url': self.server_url,
            'response': response,
            'page': page,
            'itemsPerPage': items_per_page,
            'protocol': kwargs.get('protocol', default),
            'cdm_data_type': kwargs.get('cdm_data_type', default),
            'institution': kwargs.get('institution', default),
            'ioos_category': kwargs.get('ioos_category', default),
            'keywords': kwargs.get('keywords', default),
            'long_name': kwargs.get('long_name', default),
            'standard_name': kwargs.get('standard_name', default),
            'variableName': kwargs.get('variableName', default),
            'minLon': kwargs.get('min_lon', default),
            'maxLon': kwargs.get('max_lon', default),
            'minLat': kwargs.get('min_lat', default),
            'maxLat': kwargs.get('max_lat', default),
            'minTime': kwargs.get('min_time', default),
            'maxTime': kwargs.get('max_time', default),
            'searchFor': search_for,
        }
        self.search_options.update(search_options)
        search_url = base.format(**search_options)
        _check_url_response(search_url)
        return search_url