-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-data.js
More file actions
43 lines (38 loc) · 1.02 KB
/
generate-data.js
File metadata and controls
43 lines (38 loc) · 1.02 KB
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
import Airtable from 'airtable';
import fs from 'node:fs';
import 'dotenv/config';
const env = process.env;
const base = new Airtable({ apiKey: env.AIRTABLE_READ_TOKEN }).base(env.AIRTABLE_BASE_ID);
async function getFromAirtable() {
const data = {};
const response = await base(env.AIRTABLE_TABLE_ID)
.select({
maxRecords: 1000,
pageSize: 100,
filterByFormula: '{Approved} = 1',
fields: ['British', 'American', 'Category']
})
.eachPage((records, fetchNext) => {
records.forEach((record) => {
const categoryArray = record.get('Category') || [env.GENERAL_CATEGORY] || ['General'];
categoryArray.forEach((category) => {
if (!data[category]) {
data[category] = [];
}
data[category].push([
record.get('British').toString(),
record.get('American').toString()
]);
});
});
fetchNext();
})
.then(() => {
return data;
});
return response;
}
(async () => {
const data = await getFromAirtable();
fs.writeFileSync('src/lib/data.json', JSON.stringify(data));
})();