-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
49 lines (45 loc) · 1.15 KB
/
lib.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
const notion = require("./setup.js");
const updateRows = async (
rowWork = async (...args) => console.log(...args),
limit = process.env.ROW_LIMIT || Infinity,
interval = process.env.RATE_LIMITING_INTERVAL
) => {
let cursor = undefined,
hasMore = true,
i = 0;
const databaseId = process.env.DATABASE_ID;
while (hasMore && i < limit) {
const response = await notion.databases.query({
database_id: databaseId,
filter: {
and: [
{
property: "Link",
rich_text: {
is_not_empty: true,
},
},
{
property: "URL",
url: {
is_empty: true,
},
},
],
},
sorts: [
{
property: "Created time",
direction: "descending",
},
],
});
cursor = response.cursor;
hasMore = response.has_more;
for (let j = 0; j < response.results.length && i < limit; j++, i++) {
await rowWork(response.results[j], i, response);
await new Promise((resolve, reject) => setTimeout(resolve, interval));
}
}
};
module.exports = { traverseRows };