-
Notifications
You must be signed in to change notification settings - Fork 5
/
5.1-seed-akas.js
69 lines (59 loc) · 1.27 KB
/
5.1-seed-akas.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
import { ddb, log, LineParser, LineReader } from "./helpers/index.js";
const lineParser = new LineParser();
function seed() {
let counter = 0;
let seedCounter = 0;
LineReader("title.akas", async (line) => {
if (counter++ === 0) {
lineParser.setColumn(line);
return;
}
const { titleId, ordering, title, region, language, types } =
lineParser.parse(line);
if (types !== "imdbDisplay") {
return;
}
const params = {
TableName: "Movies",
Item: {
tconst: {
S: titleId,
},
type: {
S: "akas",
},
sk: {
S: `AKAS#${titleId}#${ordering}`,
},
title: {
S: title,
},
region: {
S: region,
},
language: {
S: language,
},
},
ReturnConsumedCapacity: "TOTAL",
};
if (region === "\\N") {
delete params.Item.region;
}
if (language === "\\N") {
delete params.Item.language;
}
try {
log(counter, seedCounter);
await ddb
.putItem(params)
.promise()
.then(() => log(counter, ++seedCounter));
} catch (error) {
console.log(error);
console.log(params);
process.exit(1);
}
});
}
seed();