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)
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 maas_archive(begin, end): """ This returns a collection of JSON objects for every weather report available for October 2012: { "count": 29, "next": "http://marsweather.ingenology.com/v1/archive/?terrestrial_date_end=2012-10-31&terrestrial_date_start=2012-10-01&page=2", "previous": null, "results": [ ... ] } """ base_url = "http://marsweather.ingenology.com/v1/archive/?" try: vali_date(begin) vali_date(end) base_url += "terrestrial_date_start=" + begin + "&" + "terrestrial_date_end=" + end except: raise ValueError("Incorrect date format, should be YYYY-MM-DD") return dispatch_http_get(base_url)
def maas_archive(begin, end): ''' This returns a collection of JSON objects for every weather report available for October 2012: { "count": 29, "next": "http://marsweather.ingenology.com/v1/archive/?terrestrial_date_end=2012-10-31&terrestrial_date_start=2012-10-01&page=2", "previous": null, "results": [ ... ] } ''' base_url = 'http://marsweather.ingenology.com/v1/archive/?' try: vali_date(begin) vali_date(end) base_url += 'terrestrial_date_start=' + begin + "&" + 'terrestrial_date_end=' + end except: raise ValueError("Incorrect date format, should be YYYY-MM-DD") return dispatch_http_get(base_url)
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)
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)
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)
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)