0

The pictures are not displaying. The code executes just fine. I took out the api key.

def gimmePictures(num):
    for n in range(0,num):
        now = datetime.datetime.now()
        day4Pictures= now - datetime.timedelta(days = n)
        data = {'api_key':'', 
         'date':day4Pictures.date()}
        print(data)
        # using the paramas argument in our request
        result =  requests.get('https://api.nasa.gov/planetary/apod',params=data)
        # create a dictionary for yesterday's picture
        dict_day = result.json()
        print(dict_day['date'])
        Image(dict_day['url'])
gimmePictures(10)
  • Welcome to SO! Are you sure you want to call `gimmePictures(10)` recursively in a loop? Seems like this would blow the stack. `gimmePictures` is never called and no data is ever added to the plot, so it's not surprising that `plt.show` doesn't show anything (it's also missing parentheses to actually invoke the function). – ggorlen Nov 23 '20 at 15:56
  • Thank you! I made the change, however I still don't have photos. I thought plt.show was a long shot lol. – Jordan Greenhut Nov 23 '20 at 16:06
  • After the update, there's no plotting code at all. You can't create a plot without importing matplotlib and [showing the plot](https://stackoverflow.com/questions/8575062/how-to-show-matplotlib-plots-in-python). See [this tutorial](https://matplotlib.org/tutorials/introductory/images.html). – ggorlen Nov 23 '20 at 16:10

1 Answers1

0

How can I display an image from a file in Jupyter Notebook?

def gimmePictures(num):
    listofImageNames=[]
    for n in range(0,num):
        now = datetime.datetime.now()
        day4Pictures= now - datetime.timedelta(days = n)
        data = {'api_key':'dcS6cZ9DJ4zt9oXwjF6hgemj38bNJo0IGcvFGZZj', 'date':day4Pictures.date()}
        # using the paramas argument in our request
        result =  requests.get('https://api.nasa.gov/planetary/apod',params=data)
        # create a dictionary for yesterday's picture
        dict_day = result.json()
        listofImageNames.append(dict_day['url'])
    for imageName in listofImageNames:
        display(Image(imageName))
gimmePictures(10)