Created
September 21, 2015 22:37
-
-
Save vespakoen/ce8962b270abd3d9b69f to your computer and use it in GitHub Desktop.
Set your background to a random image from a flickr photoset
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
'use strict'; | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | |
var _nodeFetch = require('node-fetch'); | |
var _nodeFetch2 = _interopRequireDefault(_nodeFetch); | |
var _xml2js = require('xml2js'); | |
var _xml2js2 = _interopRequireDefault(_xml2js); | |
var _lodashRandom = require('lodash.random'); | |
var _lodashRandom2 = _interopRequireDefault(_lodashRandom); | |
function parseXML(xml) { | |
return new Promise(function (resolve, reject) { | |
_xml2js2['default'].parseString(xml, function (err, res) { | |
if (err) return reject(err); | |
resolve(res); | |
}); | |
}); | |
} | |
(0, _nodeFetch2['default'])('https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=31e2c7e110ca8b9845bd8e5cc56ea584&photoset_id=72157657849361828&user_id=136002919@N02').then(function (res) { | |
return res.text(); | |
}).then(function (body) { | |
return parseXML(body); | |
}).then(function (json) { | |
setInterval(function () { | |
var randomPicIndex = (0, _lodashRandom2['default'])(0, json.rsp.photoset[0].photo.length); | |
var randomPic = json.rsp.photoset[0].photo[randomPicIndex].$; | |
return (0, _nodeFetch2['default'])('https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=31e2c7e110ca8b9845bd8e5cc56ea584&photo_id=' + randomPic.id).then(function (res) { | |
return res.text(); | |
}).then(function (body) { | |
return parseXML(body); | |
}).then(function (json) { | |
var sizes = json.rsp.sizes[0].size; | |
console.log('feh --bg-scale ' + sizes[sizes.length - 1].$.source); | |
}); | |
}, 1000 * 5); | |
}); |
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
import fetch from 'node-fetch'; | |
import xml2js from 'xml2js'; | |
import random from 'lodash.random'; | |
var FLICKR_API_KEY = process.env.FLICKR_API_KEY; // 31e2c7e110ca8b9845bd8e5cc56ea584 | |
var FLICKR_PHOTOSET_ID = process.env.FLICKR_PHOTOSET_ID; // 72157657849361828 | |
var FLICKR_USER_ID = process.env.FLICKR_USER_ID; //136002919@N02 | |
function parseXML(xml) { | |
return new Promise((resolve, reject) => { | |
xml2js.parseString(xml, (err, res) => { | |
if (err) return reject(err); | |
resolve(res); | |
}); | |
}); | |
} | |
fetch('https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=' + FLICKR_API_KEY + '&photoset_id=' + FLICKR_PHOTOSET_ID + '&user_id=' + FLICKR_USER_ID) | |
.then((res) => res.text()) | |
.then((body) => parseXML(body)) | |
.then((json) => { | |
setInterval(() => { | |
var randomPicIndex = random(0, json.rsp.photoset[0].photo.length); | |
var randomPic = json.rsp.photoset[0].photo[randomPicIndex].$; | |
return fetch('https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=' + FLICKR_API_KEY + '&photo_id=' + randomPic.id) | |
.then((res) => res.text()) | |
.then((body) => parseXML(body)) | |
.then((json) => { | |
var sizes = json.rsp.sizes[0].size; | |
console.log('feh --bg-scale ' + sizes[sizes.length - 1].$.source); | |
}); | |
}, 1000 * 5); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment