Last active
October 7, 2018 00:46
-
-
Save EricsonWillians/a483f9f1daa76a548dba9babf7917a97 to your computer and use it in GitHub Desktop.
Script to open on the web browser the latest image of Earth taken by NASA/DSCOVR's Earth Polychromatic Imaging Camera.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Copyright (C) <2018> <Ericson Willians> | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
""" | |
import sys | |
import os | |
import urllib.request | |
import json | |
import dateutil.parser | |
def open_url(url): | |
if sys.platform == "win32": | |
os.startfile(url) | |
elif sys.platform == "darwin": | |
subprocess.Popen(['open', url]) | |
else: | |
try: | |
subprocess.Popen(["xdg-open", url]) | |
except OSError: | |
print('Please open a browser on: ' + url) | |
if __name__ == "__main__": | |
api_key = "fabLflcbOsvl87dvvxls87Tx2qFk3fMaQMbxk7li" | |
get_request = "https://api.nasa.gov/EPIC/api/natural?api_key=" + api_key | |
data = json.loads(urllib.request.urlopen(get_request).read())[0] | |
date = dateutil.parser.parse(data["date"]) | |
image = data["image"] | |
fix_0_variance = lambda x: '0' + str(x) if x < 10 else str(x) | |
url = "https://epic.gsfc.nasa.gov/archive/natural/" + str(date.year) + "/" + fix_0_variance(date.month) + "/" + fix_0_variance(date.day) + "/png/" + image + ".png" | |
open_url(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment