NasaPod Image Scrapper

As a windows phone user, i rarely have the chance to get myself some good apps available as cross platform apps. On a grungy day, happened to encounter an app. NASAPOD IMAGE OF THE DAY at hands and i had to 9GAG myself for my overwhelming joy for an app showing cool images in my HD display Lumia 640.

The images are not of high resoluted or of quality but it seems cool to me holding a galaxy/constellation image as my wallpaper or lockscreener. Dreams of having those images in my PC haunted some hours and decided to test my skills in a code that hovers the respective webpage to download the daily images for me.

Here’s the Code at the table. .

import urllib
from bs4 import BeautifulSoup
from time import gmtime, strftime
import os

url = 'http://apod.nasa.gov/apod/'
soup = BeautifulSoup(urllib.urlopen(url).read())
temp = soup.img['src']
myPath = # your file path
full_url = url + temp
title = (soup.body.b.text).strip('\n') + '.jpg'
nasa = os.path.join(myPath, title)
urllib.urlretrieve(full_url,nasa)
details =  (title , strftime("%Y-%m-%d %H:%M:%S", gmtime()))

with open('/mypath/apod_imagedb.txt','wb+') as f:
  f.write(str(details))
  f.close()
*****
Written by Thilip Varadharajan on 02 January 2016