nasa / apod-api

Astronomy Picture of the Day API service
Apache License 2.0
810 stars 155 forks source link

Wonder if it is possible to have an earth-api using Earth Observatory - Anyone want to investigate how possible this might be? #41

Open JustinGOSSES opened 4 years ago

JustinGOSSES commented 4 years ago

https://earthobservatory.nasa.gov/about

Wonder if it is possible to have an earth-api using Earth Observatory - Anyone want to investigate how possible this might be?

vn7n24fzkq commented 4 years ago

Hi, I am interested with this. I will take time to investigate on weekend.

vn7n24fzkq commented 4 years ago

I found a way to get picture like apod-api.

    https://earthobservatory.nasa.gov/images/getRecords?filters=null&dateStart={timestamp}&dateEnd={timestamp}

The response will looks like this

{
    "current_page": 1,
    "data": [
        {
            "id": 146225,
            "title": "Flood Waters Overwhelm Northern Madagascar",
            "caption_short": "Parts of the island nation saw double the usual amount of monthly rainfall.",
            "thumbnail_file": "madagascar_oli_2020027_th.jpg",
            "guid": null,
            "post_date": "2020-01-30 13:43:07",
            "type": "image",
            "image_path": "https://eoimages.gsfc.nasa.gov/images/imagerecords/146000/146225/",
            "slug": "/images/146225/flood-waters-overwhelm-northern-madagascar",
            "date_raw": "2020-01-30 13:43:07",
            "date_formatted": "Published Jan 30, 2020",
            "type_display": "Image",
            "topics": {
                "imageofday": "Image of the Day",
                "land": "Land",
                "water": "Water",
                "floods": "Floods",
                "human": "Human Presence",
                "landslides": "Landslides"
            }
        }
    ],
    "first_page_url": "https://earthobservatory.nasa.gov/images/getRecords?page=1",
    "from": 1,
    "last_page": 1,
    "last_page_url": "https://earthobservatory.nasa.gov/images/getRecords?page=1",
    "next_page_url": null,
    "path": "https://earthobservatory.nasa.gov/images/getRecords",
    "per_page": 5,
    "prev_page_url": null,
    "to": 1,
    "total": 1
}

Get first data in data array, maybe the topics contains "Image of the Day" ?

Now, you can get thumbnail image by use image_path append with thumbnail_file.

The page url is the api host append slug Should looks like this.

https://earthobservatory.nasa.gov/images/146225/flood-waters-overwhelm-northern-madagascar

Get the page

Parse the html and find the element contains class="download-btn download-btn-first no-underline pull-right hvr-rectangle-out" and the href value is the image url.

JustinGOSSES commented 4 years ago

Excellent work @vn7n24fzkq -

Anyone attempted to check if this pattern holds across many dates ?

JustinGOSSES commented 4 years ago

@vn7n24fzkq can you provide the format of the timestamp you got to work? I put in a variety of timestamp formats but none of them seemed to be the right one.

vn7n24fzkq commented 4 years ago

@JustinGOSSES I use uinx timestamp like this site provide. https://www.unixtimestamp.com/index.php If I use timestamp start at 01/01/2012 @ 12:00am (UTC) to 02/01/2012 @ 12:00am (UTC), it would be https://earthobservatory.nasa.gov/images/getRecords?dateStart=1325376000&dateEnd=1328054400

Here is the response

{"current_page":1,"data":[{"id":77046,"title":"100 Years at Kilauea","caption_short":"January 2012 marks the 100th anniversary of the Hawaiian Volcano Observatory, situated on the rim of Kilauea Caldera.","thumbnail_file":"kilauea_ali_2012028_tn.jpg","guid":null,"post_date":"2012-01-31 00:00:00","type":"image","image_path":"https:\/\/eoimages.gsfc.nasa.gov\/images\/imagerecords\/77000\/77046\/","slug":"\/images\/77046\/100-years-at-kilauea","date_raw":"2012-01-31 00:00:00","date_formatted":"Published Jan 31, 2012","type_display":"Image","topics":{"imageofday":"Image of the Day","land":"Land","volcanoes":"Volcanoes","human":"Human Presence"}},{"id":77039,"title":"Pay\u00c3\u00ban Matru Volcanic Field, Argentina","caption_short":"East of the Andes, the volcanic field is a product of complex geological processes.","thumbnail_file":"ISS030-E-030265_tn.jpg","guid":null,"post_date":"2012-01-30 00:00:00","type":"image","image_path":"https:\/\/eoimages.gsfc.nasa.gov\/images\/imagerecords\/77000\/77039\/","slug":"\/images\/77039\/payaon-matru-volcanic-field-argentina","date_raw":"2012-01-30 00:00:00","date_formatted":"Published Jan 30, 2012","type_display":"Image","topics":{"imageofday":"Image of the Day","land":"Land"}},{"id":76972,"title":"Isle of Man","caption_short":"This small island has a complicated geologic history.","thumbnail_file":"isleofman_etm_2001121_tn.jpg","guid":null,"post_date":"2012-01-29 00:00:00","type":"image","image_path":"https:\/\/eoimages.gsfc.nasa.gov\/images\/imagerecords\/76000\/76972\/","slug":"\/images\/76972\/isle-of-man","date_raw":"2012-01-29 00:00:00","date_formatted":"Published Jan 29, 2012","type_display":"Image","topics":{"imageofday":"Image of the Day","land":"Land"}},{"id":77042,"title":"Istanbul, Turkey","caption_short":"The population of Turkey’s economic and cultural center has exploded in recent decades.","thumbnail_file":"istanbul_tm5_2011158_432_tn.jpg","guid":null,"post_date":"2012-01-28 00:00:00","type":"image","image_path":"https:\/\/eoimages.gsfc.nasa.gov\/images\/imagerecords\/77000\/77042\/","slug":"\/images\/77042\/istanbul-turkey","date_raw":"2012-01-28 00:00:00","date_formatted":"Published Jan 28, 2012","type_display":"Image","topics":{"imageofday":"Image of the Day","human":"Human Presence","world of change":"World of Change"}},{"id":77031,"title":"Tropical Cyclone Funso ","caption_short":"Powerful Cyclone Funso has spent the last week drenching Mozambique with flood-inducing rain as it slowly churned down the Mozambique Channel.","thumbnail_file":"Funso_amo_2012026_tn.jpg","guid":null,"post_date":"2012-01-27 00:00:00","type":"image","image_path":"https:\/\/eoimages.gsfc.nasa.gov\/images\/imagerecords\/77000\/77031\/","slug":"\/images\/77031\/tropical-cyclone-funso","date_raw":"2012-01-27 00:00:00","date_formatted":"Published Jan 27, 2012","type_display":"Image","topics":{"imageofday":"Image of the Day","atmosphere":"Atmosphere","water":"Water","severe storms":"Severe Storms"}}],"first_page_url":"https:\/\/earthobservatory.nasa.gov\/images\/getRecords?page=1","from":1,"last_page":11,"last_page_url":"https:\/\/earthobservatory.nasa.gov\/images\/getRecords?page=11","next_page_url":"https:\/\/earthobservatory.nasa.gov\/images\/getRecords?page=2","path":"https:\/\/earthobservatory.nasa.gov\/images\/getRecords","per_page":5,"prev_page_url":null,"to":5,"total":53}
JustinGOSSES commented 2 years ago

FYI for everyone, the earth-imagery API on api.nasa.gov has been open-sourced here: https://github.com/nasa/earth-imagery-api