Skip to content

Instantly share code, notes, and snippets.

@quinncomendant
Last active September 13, 2018 22:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save quinncomendant/1209964b9124c2053be7 to your computer and use it in GitHub Desktop.
Save quinncomendant/1209964b9124c2053be7 to your computer and use it in GitHub Desktop.
This is an OS X command-line script that downloads the latest DSCOVR:EPIC <http://epic.gsfc.nasa.gov/> image and sets it as your desktop picture. Prerequisites: requires installing Homebrew <http://brew.sh/> and then the jshon tool (`brew install jshon`). Then you can run the command manually, or add it to your crontab.
#!/usr/bin/env bash
download_directory="$HOME/Desktop/_dl/epic-earth";
apiurl="http://epic.gsfc.nasa.gov/api/images.php";
curl -s "$apiurl" | jshon -a -e image -u | while read image; do
destfile="$download_directory/$image.jpg";
mkdir -p "$download_directory";
if [[ -n "$image" && ! -f "$destfile" ]]; then
echo "New 🌍 ! $image.jpg";
curl -so "$destfile" "http://epic.gsfc.nasa.gov/epic-archive/jpg/$image.jpg";
ln -sf "$destfile" "$download_directory/latest.jpg";
fi
done
latestfile=$(readlink -f "$download_directory/latest.jpg");
if [[ -e "$latestfile" && $(stat -c '%Y' "$latestfile") -gt $(($(date +'%s') - 60)) ]]; then
# If latest file exists, and it's last modification time less than than 1 minute, set it to desktop.
osascript -e "tell application \"Finder\" to set desktop picture to POSIX file \"$latestfile\"";
killall Dock;
fi
#####################################################################
# EPIC Daily “Blue Marble” API documentation:
#####################################################################
# The API URL is:
# http://epic.gsfc.nasa.gov/api/images.php
#
# This gets you a list of the latest day’s images & metadata.
#
# OR
#
# http://epic.gsfc.nasa.gov/api/images.php?date=YYYY-M-D&w=X&e=Y
#
# The second form’s optional parameters allow you to focus in to
# geographical regions that were in view (technically, longitudinal
# bounding points) on a given date.
#
# For instance: Using North America’s boundaries of east =
# -53.034, and west = -170.859 and choosing August 24, 2015, the URL
# would look like this:
#
# http://epic.gsfc.nasa.gov/api/images.php?date=2015-8-24&w=--170.859&e=-53.034
#
# The date parameter is unpadded(e.g. 2015-9-1, vs. 2015-09-01 for
# September 1, 2015), and optional. Leaving the date off will default to
# the latest image set.
#
# Leaving out the coordinates gets you every image for whatever date is
# returned.
# Adding either longitudinal parameter returns all images for the given
# date, for which the supplied longitude is in view of the camera.
#
# The JSON data looks like this:
#
# ImageData object:
#
# {
# "image": "epic_1b_20150826231708_00", // image name sans extension.
# "caption": "About an image", // Will contain a caption
# "coords": “{}", // Contains a JSON string representing a
# Coordinates object.
# "date": "2015-08-26 23:17:08" // The date the capture sequence for the
# data was initiated
# }
#
# ImageData notes:
#
# For the image field to be useful, it has to be added to a URL. Image
# URLs differ depending upon purpose.
#
# Given an image name of “epic_1b_20150901205648_00” (taken
# Sept 1, 2015, with the camera aimed
# at 3 storms in the pacific (my favorite)), we have URLs as follows:
#
# For compressed JPG thumbnails, the URL would be:
#
# http://epic.gsfc.nasa.gov/epic-archive/thumbs/epic_1b_20150901205648_00.jpg
#
# For full-size, compressed JPG previews, the URL would be:
#
# http://epic.gsfc.nasa.gov/epic-archive/jpg/epic_1b_20150901205648_00.jpg
#
# For full-size original PNG images with full metadata in the comments,
# the URL would be:
#
# http://epic.gsfc.nasa.gov/epic-archive/png/epic_1b_20150901205648_00.png
#
# Coordinates object
#
# {
# "centroid_coordinates": { // Geographical coordinates that the
# satellite is looking at
# "lat": 4.076132,
# "lon": -169.648562
# },
# "dscovr_j2000_position": { // Position of the satellite in space
# "x": -1439710.750000,
# "y": 659227.437500,
# "z": 113316.414062
# },
# "lunar_j2000_position": { // Position of the moon in space
# "x": 153199.062500,
# "y": -319797.531250,
# "z": -104905.093750
# },
# "sun_j2000_position": { // Position of the sun in space
# "x": -134918656.000000,
# "y": 62555808.000000,
# "z": 27119770.000000
# },
# "attitude_quaternions": { // Satellite attitude
# "q0": 0.976360,
# "q1": -0.212080,
# "q2": -0.039540,
# "q3": 0.013750
# }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment