-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLexiconMetadata.js
77 lines (70 loc) · 2.1 KB
/
getLexiconMetadata.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
73
74
75
76
77
const Airtable = require('airtable');
const fs = require('fs');
const path = require('path');
const identifier = process.argv[2];
const repo = process.argv[3];
const destination = process.argv[4];
const fileIdentifier = process.argv[5];
require('dotenv').config({ path: repo + '/.env' });
const base = new Airtable({apiKey: process.env.APIKEY}).base(process.env.BASE);
const TABLE = 'Lexicons';
const VIEW = 'Public Archival View';
const CELL_FORMAT = 'string';
const TIME_ZONE = 'America/New_York';
const USER_LOCALE = 'en-ca';
const ID_FIELD = 'Identifier';
const FIELDS = [
'Identifier',
'Title',
'Subject [Languages]',
'Creator',
'Description',
'Date [Created]',
'Subject [Source Language: Genealogy]',
'Subject [Source Language: Continent]',
'Subject [Source Language: Nation]',
'Language [Source]',
'Language [Source: ISO 639-3]',
'Language [Source: Glottocode]',
'Language [Source Dialect: Glottocode]',
'Language [Source Macrolanguage: ISO 639-3]',
'Language [Target]',
'Language [Target: ISO 639-3]',
'Language [Target: Glottocode]',
'Language [Target Dialect: Glottocode]',
'Language [Target Macrolanguage: ISO 639-3]',
'Publisher',
'Format [Medium]',
'Format [Extent]',
'Relation [Requires]',
'Type',
'Type [Document: LOC]',
'Type [Document Category: LOC]',
'Coverage [Nation]',
'Coverage [Territory]',
'Coverage [Dropbox]',
'Coverage [Web]',
'Relation [Is Version Of]',
'Relation [Is Part Of]',
'Rights'
];
base(TABLE).select({
view: VIEW,
cellFormat: CELL_FORMAT,
timeZone: TIME_ZONE,
userLocale: USER_LOCALE,
filterByFormula: `${ID_FIELD}='${identifier}'`,
fields: FIELDS
}).firstPage((err, records) => {
if (err) {
console.error(err);
return process.exit(1);
}
if (records.length !== 1) {
console.error(`${records.length} records found for identifier ${identifier}`);
return process.exit(1);
}
const record = records[0];
const content = FIELDS.map(field => `${field}: ${record.get(field)}`).join('\n');
fs.writeFileSync(`${path.resolve(destination)}/${fileIdentifier}/${fileIdentifier}__metadata.txt`, content);
});