-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (34 loc) · 1.04 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
const { Client } = require("@notionhq/client")
const dotenv = require("dotenv")
const axios = require('axios').default;
dotenv.config()
const notion = new Client({ auth: process.env.NOTION_KEY })
const notionPageId = process.env.NOTION_PAGE_ID
const bingUrlDaily = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"
const getBingImageUrl = async () => {
const imageUrl = await axios.get(bingUrlDaily).then(response => {
const { data } = response
return data.images[0].url
})
return `https://www.bing.com${imageUrl}`
}
function updateNotionImageDaily(bingImage) {
notion.pages.update({
page_id: notionPageId,
cover: {
"external": {
url: bingImage,
},
"type": "external",
},
})
.catch((error) => {
console.log(error)
})
.then(() => {
console.log("\n✅ Notion database is synced with Bing.")
})
}
getBingImageUrl().then((bingImage) => {
updateNotionImageDaily(bingImage)
})