-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
72 lines (62 loc) · 2.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* @file Example of wonderful-bing-wallpaper
* @author Surmon <https://github.com/surmon-china>
*/
const xml2js = require('xml2js')
const WonderfulBingWallpaper = require('../dist/bing.cjs')
const resolutions = WonderfulBingWallpaper.getResolutions()
const wbw = new WonderfulBingWallpaper({
size: 8,
day: 7,
resolution: resolutions[2],
host: 'cn.bing.com',
local: 'zh-cn',
})
console.log('wallPaper', wbw)
console.log('\nwallPaper resolutions', resolutions, resolutions[3])
// default json
wbw.getWallpapers().then(wallpaperJSON => {
console.group('wallpaperJSON-1')
console.log('got wallpaperJSON-1 data', wallpaperJSON)
console.log(`\ngot wallpaperJSON-1 humanizeWallpapers data :url = ${resolutions[2]}\n`, wbw.humanizeWallpapers(wallpaperJSON))
console.log(`\ngot wallpaperJSON-1 humanizeWallpapers data :url = ${resolutions[3]}\n`, wbw.humanizeWallpapers(wallpaperJSON, resolutions[3]))
console.log(`\ngot wallpaperJSON-1[0] humanizeWallpapers data :url = ${resolutions[2]}\n`, wbw.humanizeWallpapers(wallpaperJSON[0]))
console.log(`\ngot wallpaperJSON-1[0] humanizeWallpapers data :url = ${resolutions[5]}\n`, wbw.humanizeWallpapers(wallpaperJSON[0], resolutions[5]))
console.groupEnd()
})
// params json
wbw.getWallpapers({ size: 10, day: 2 }).then(wallpaperJSON => {
console.group('wallpaperJSON-2')
console.log('got wallpaperJSON-2 data', wallpaperJSON)
console.log('got wallpaperJSON-2 humanizeWallpapers data', wbw.humanizeWallpapers(wallpaperJSON))
console.log('got wallpaperJSON-2[0] humanizeWallpapers data\n', wbw.humanizeWallpapers(wallpaperJSON[0]))
console.groupEnd()
})
wbw.setOptions({ ensearch: 1 })
// ensearch
wbw.getWallpapers().then(wallpaperJSON => {
console.group('wallpaperJSON-3')
console.log('got wallpaperJSON-3 data', wallpaperJSON)
console.log('got wallpaperJSON-3 humanizeWallpapers data', wbw.humanizeWallpapers(wallpaperJSON))
console.groupEnd()
})
// xml
wbw.getWallpapers({ format: 'xml' }).then(wallpaperXML => {
console.group('wallpaperXML')
console.debug('got wallpaperXML data\n', wallpaperXML)
xml2js.parseString(wallpaperXML, (err, result) => {
console.log('wallpaperXML', result)
})
console.groupEnd()
})
// setOptions
wbw.setOptions({ size: 3 })
// rss
wbw.getWallpapers({ format: 'rss' }).then(wallpaperRSS => {
console.group('wallpaperRSS')
console.debug('got wallpaperRSS data\n', wallpaperRSS)
xml2js.parseString(wallpaperRSS, (err, result) => {
console.log('wallpaperRSS', result)
})
console.groupEnd()
})