├── README.md ├── package.json ├── app.js └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # bing wallpaper 2 | 3 | ### crontab 4 | 5 | #min hour mday month wday command 6 | 20 9,12,15,19,22 * * * /usr/local/bin/node ~/path/to/bingwallpaper/app.js 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bing_wallpaper", 3 | "version": "0.0.0", 4 | "description": "daily bing wallpaper", 5 | "main": "app.js", 6 | "dependencies": { 7 | "request": "^2.51.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | //http://stackoverflow.com/questions/10639914/is-there-a-way-to-get-bings-photo-of-the-day 2 | 3 | var fs = require('fs') 4 | var path = require('path') 5 | 6 | var request = require('request') 7 | 8 | function fetch(){ 9 | var uri = 'http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1' 10 | 11 | request(uri, function(error, response, body){ 12 | try { 13 | var data = JSON.parse(body) 14 | var images = data.images 15 | 16 | var pictures = path.join(__dirname, '../../Pictures/bing-wallpapers/') 17 | 18 | images.forEach(function(image){ 19 | var ext = path.extname(image.url).split('&')[0] 20 | var img = path.join(pictures, image.fullstartdate + ext) 21 | 22 | if (!fs.existsSync(img)) { 23 | request(`https://www.bing.com${image.url}`).pipe( 24 | fs.createWriteStream(img) 25 | ) 26 | } else { 27 | console.log('already exists') 28 | } 29 | }) 30 | } catch (e) { 31 | console.error(e) 32 | } 33 | }) 34 | } 35 | 36 | fetch() 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Miko Gao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | --------------------------------------------------------------------------------