Beispiel #1
0
def apod(date=None, concept_tags=None):
    '''
    HTTP REQUEST

    GET https://api.nasa.gov/planetary/apod

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    date	YYYY-MM-DD	today	The date of the APOD image to retrieve
    concept_tags	bool	False	Return an ordered dictionary of concepts from the APOD explanation
    api_key	string	DEMO_KEY	api.nasa.gov key for expanded usage
    EXAMPLE QUERY

    https://api.nasa.gov/planetary/apod?concept_tags=True&api_key=DEMO_KEY
    '''
    base_url = "https://api.nasa.gov/planetary/apod?"

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")
    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Beispiel #2
0
def apod(date=None, concept_tags=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/planetary/apod

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    date	YYYY-MM-DD	today	The date of the APOD image to retrieve
    concept_tags	bool	False	Return an ordered dictionary of concepts from the APOD explanation
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/planetary/apod?concept_tags=True&api_key=DEMO_KEY
    '''
    base_url = "http://api.data.gov/nasa/planetary/apod?"

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")
    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
def address(address=None, begin=None, end=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/planetary/earth/temperature/address

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    text	string	n/a	Address string
    begin	int	1880	beginning year for date range, inclusive
    end	int	2014	end year for date range, inclusive
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/planetary/earth/temperature/address?text=1800 F Street, NW, Washington DC&begin=1990
    '''
    base_url = "http://api.data.gov/nasa/planetary/earth/temperature/address?"

    if not address:
        raise ValueError(
            "address is missing, which is mandatory. example : 1800 F Street, NW, Washington DC")
    elif not isinstance(address, str):
        try:
            address = str(address)
        except:
            raise ValueError("address has to be type of string")
    else:
        base_url += "text=" + address + "&"

    if not begin:
        raise ValueError(
            "Begin year is missing, which is mandatory. Format : YYYY")
    else:
        try:
            validate_year(begin)
            base_url += "begin=" + begin + "&"
        except:
            raise ValueError("Incorrect begin year format, should be YYYY")

    if end:
        try:
            validate_year(end)
            base_url += "end=" + end + "&"
        except:
            raise ValueError("Incorrect end year format, should be YYYY")

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Beispiel #4
0
def patents(query=None, concept_tags=None, limit=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/patents

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    query	string	None	Search text to filter results
    concept_tags	bool	False	Return an ordered dictionary of concepts from the patent abstract
    limit	int	all	number of patents to return
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/patents/content?query=temperature&limit=5&api_key=DEMO_KEY

    '''
    base_url = "http://api.data.gov/nasa/patents/content?"

    if not query:
        raise ValueError("search query is missing, which is mandatory.")
    elif not isinstance(query, str):
        try:
            query = str(query)
        except:
            raise ValueError("query has to be type of string")
    else:
        base_url += "query=" + query + "&"

    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it"
            )

        base_url += "limit=" + str(limit) + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Beispiel #5
0
def patents(query=None, concept_tags=None, limit=None):
    '''
    HTTP REQUEST

    GET https://api.nasa.gov/patents

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    query	string	None	Search text to filter results
    concept_tags	bool	False	Return an ordered dictionary of concepts from the patent abstract
    limit	int	all	number of patents to return
    api_key	string	DEMO_KEY	api.nasa.gov key for expanded usage
    EXAMPLE QUERY

    https://api.nasa.gov/patents/content?query=temperature&limit=5&api_key=DEMO_KEY

    '''
    base_url = "https://api.nasa.gov/patents/content?"

    if not query:
        raise ValueError("search query is missing, which is mandatory.")
    elif not isinstance(query, str):
        try:
            query = str(query)
        except:
            raise ValueError("query has to be type of string")
    else:
        base_url += "query=" + query + "&"

    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it")

        base_url += "limit=" + str(limit) + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Beispiel #6
0
def assets(lon=None, lat=None, begin=None, end=None):
    '''
    HTTP REQUEST

    GET https://api.nasa.gov/planetary/earth/assets

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    lat	float	n/a	Latitude
    lon	float	n/a	Longitude
    begin	YYYY-MM-DD	n/a	beginning of date range
    end	        YYYY-MM-DD	today	end of date range
    api_key	string	DEMO_KEY	api.nasa.gov key for expanded usage
    EXAMPLE QUERY

    https://api.nasa.gov/planetary/earth/assets?lon=100.75&lat=1.5&begin=2014-02-01&api_key=DEMO_KEY
    '''
    base_url = "https://api.nasa.gov/planetary/earth/assets?"

    if not lon or not lat:
        raise ValueError(
            "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer 
            # (in fact, your standard C library) stores them as binary. 
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")

    if not begin:
        raise ValueError(
            "Begin date is missing, which is mandatory. Format : YYYY-MM-DD")
    else:
        try:
            vali_date(begin)
            base_url += "begin=" + begin + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if end:
        try:
            vali_date(end)
            base_url += "end=" + end + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Beispiel #7
0
def imagery(lon=None, lat=None, dim=None, date=None, cloud_score=None):
    '''
    # ----------QUERY PARAMETERS----------

    # Parameter	Type	Default	Description
    # lat	float	n/a	Latitude
    # lon	float	n/a	Longitude
    # dim	float	0.025	width and height of image in degrees
    # date	YYYY-MM-DD  today	date of image ----if not supplied, then the most recent image (i.e., closest to today) is returned
    #cloud_score	bool	False	calculate the percentage of the image covered by clouds
    #api_key	string	vDEMO_KEY	api.nasa.gov key for expanded usage

    # ---------EXAMPLE QUERY--------

    # https://api.nasa.gov/planetary/earth/imagery?lon=100.75&lat=1.5&date=2014-02-01&cloud_score=True&api_key=DEMO_KEY

    '''

    base_url = "https://api.nasa.gov/planetary/earth/imagery?"

    if not lon or not lat:
        raise ValueError(
            "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer 
            # (in fact, your standard C library) stores them as binary. 
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")

    if dim:
        try:
            validate_float(dim)
            dim = decimal.Decimal(dim)
            base_url += "dim=" + str(dim) + "&"
        except:
            raise ValueError("imagery endpoint expects dim to be a float")

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if cloud_score == True:
        base_url += "cloud_score=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Beispiel #8
0
def assets(lon=None, lat=None, begin=None, end=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/planetary/earth/assets

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    lat	float	n/a	Latitude
    lon	float	n/a	Longitude
    begin	YYYY-MM-DD	n/a	beginning of date range
    end	        YYYY-MM-DD	today	end of date range
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/planetary/earth/assets?lon=100.75&lat=1.5&begin=2014-02-01&api_key=DEMO_KEY
    '''
    base_url = "http://api.data.gov/nasa/planetary/earth/assets?"

    if not lon or not lat:
        raise ValueError(
            "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
        )
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer
            # (in fact, your standard C library) stores them as binary.
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
            )

    if not begin:
        raise ValueError(
            "Begin date is missing, which is mandatory. Format : YYYY-MM-DD")
    else:
        try:
            vali_date(begin)
            base_url += "begin=" + begin + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if end:
        try:
            vali_date(end)
            base_url += "end=" + end + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Beispiel #9
0
def imagery(lon=None, lat=None, dim=None, date=None, cloud_score=None):
    '''
    # ----------QUERY PARAMETERS----------

    # Parameter	Type	Default	Description
    # lat	float	n/a	Latitude
    # lon	float	n/a	Longitude
    # dim	float	0.025	width and height of image in degrees
    # date	YYYY-MM-DD  today	date of image ----if not supplied, then the most recent image (i.e., closest to today) is returned
    #cloud_score	bool	False	calculate the percentage of the image covered by clouds
    #api_key	string	vDEMO_KEY	api.data.gov key for expanded usage

    # ---------EXAMPLE QUERY--------

    # https://api.data.gov/nasa/planetary/earth/imagery?lon=100.75&lat=1.5&date=2014-02-01&cloud_score=True&api_key=DEMO_KEY

    '''

    base_url = "http://api.data.gov/nasa/planetary/earth/imagery?"

    if not lon or not lat:
        raise ValueError(
            "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
        )
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer
            # (in fact, your standard C library) stores them as binary.
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
            )

    if dim:
        try:
            validate_float(dim)
            dim = decimal.Decimal(dim)
            base_url += "dim=" + str(dim) + "&"
        except:
            raise ValueError("imagery endpoint expects dim to be a float")

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if cloud_score == True:
        base_url += "cloud_score=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)