• Home
  • About
    • Zarwis Talks Here photo

      Zarwis Talks Here

    • Learn More
    • Twitter
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Using NASA api

12 Aug 2018

Reading time ~1 minute

Gathering data using NASA api

This blog post mainly focuses on using NASA’s apis (there are several of them) and handling the data given by the api.

So let’s get our hands dirty, Initially we need to get the api_key from nasa so that we can make more than a 1000 request per hour.

In order to do that, go to api_link

Now, let us use this api to get image of the day from nasa’s api I’ll be using python for this

step one,

import requests
import json
import os
import chardet

step two,

get the data from url

url = "https://api.nasa.gov/planetary/apod?api_key={}".format(api_key)

here api_key is the key that you’ve received after registering in NASA api base.

step three, get the json data from the following function,

def get_json_data(url):
    '''
    :input: url <class 'str'>
    :return: list of dictionaries
    '''
    request = requests.get(url)
    content = json.loads(request.content.decode(chardet.detect(request.content)["encoding"]))
    return content

give the url to get_json_data() function

content = get_json_data(url)

download the image using wget

os.system('wget {}'.format(content['hdurl']))


Share Tweet +1