Last active
April 4, 2020 08:45
-
-
Save jagedn/8d7244d0595a27001b2c37fceb631be9 to your computer and use it in GitHub Desktop.
Download Picture of the Day from NASA and add the explanation
This file contains hidden or 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
import javax.imageio.ImageIO | |
json = new groovy.json.JsonSlurper().parse("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY".toURL()) | |
url = json.url | |
ext = url.split('\\.').last().toLowerCase() | |
if( ['jpg','png','jpeg'].contains(ext) == false ){ | |
return | |
} | |
image = ImageIO.read(url.toURL()) | |
g = image.graphics | |
g.font = g.font.deriveFont(25f) | |
lines = json.explanation.take(300).split("(?<=\\G.{100})")+["","Made with \u2665 by Puravida Software"] | |
lines.eachWithIndex{ str, idx -> | |
g.drawString str, 20, 20+(idx*30) | |
} | |
g.dispose() | |
ImageIO.write(image, "jpg", new File("${System.getProperty("user.home")}/Pictures/nasa.jpg")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have this script in a crontab every 12h to refresh my desktop banckground
But most time I was curious about the picture, so I added the explanation in the top corner
example:
