Skip to content

Instantly share code, notes, and snippets.

@luismoramedina
Created August 10, 2016 14:44
Show Gist options
  • Save luismoramedina/54d0fabc9a87d763cc77540575327c7b to your computer and use it in GitHub Desktop.
Save luismoramedina/54d0fabc9a87d763cc77540575327c7b to your computer and use it in GitHub Desktop.
set background gopro photo of the day ubuntu
#!/usr/bin/env groovy
def proxyParams = ""
def jsonUri = "https://api.gopro.com/v2/channels/feed/playlists/photo-of-the-day.json?platform=web"
//def data = get(jsonUri)
def commandJson = "wget -q -O - " + jsonUri + proxyParams
def data = commandJson.execute().text
json = new groovy.json.JsonSlurper().parseText(data)
def image = json.media.thumbnails.full.image[0]
def file = '/tmp/goprotoday.jpg'
//download(image, file)
def commandGetPhoto = "wget " + image + " -O " + file + " " + proxyParams
commandGetPhoto.execute()
Thread.sleep(3000) //wait for the download process
def commandSetBg = "gsettings set org.gnome.desktop.background picture-uri file://" + file
commandSetBg.execute()
/*groovy style http*/
private String get(url) {
new URL(url).getText()
}
public void download(address, file) {
new File(file).withOutputStream { out ->
out << new URL(address).openStream()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment