This repository was archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
58 lines (51 loc) · 1.38 KB
/
index.ts
File metadata and controls
58 lines (51 loc) · 1.38 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { exec } from "child_process";
import dotenv from "dotenv";
import { mkdirSync } from "fs";
import { getCacheDir } from "./cache";
import { getAll, truncateQuotations } from "./coa";
import { writeCsvMapping } from "./csv";
const scrapes: Promise<
{
name: string;
scrape: () => Promise<void>;
}[]
> = Promise.all(
["bedetheque", "comicsmania", "seriesam", "gocollect"].map(
async (scrapeName) => ({
name: scrapeName,
scrape: (await import(`./scrapes/${scrapeName}`)).scrape,
})
)
);
dotenv.config({ path: ".env.local" });
(async () => {
await truncateQuotations();
mkdirSync(getCacheDir(), { recursive: true });
let hasFailed = false;
for (const { name, scrape } of await scrapes) {
try {
console.log(`Scraping ${name}, start date: ${new Date().toISOString()}`);
await scrape();
console.log(`Scrape done, end date: ${new Date().toISOString()}`);
} catch (e) {
console.error(`Scrape failed: ${e}`);
hasFailed = true;
}
}
if (hasFailed) {
process.exit(1);
}
await writeCsvMapping(await getAll());
exec("sh bump-dump.sh", (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`);
process.exit(1);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
process.exit(0);
}
console.log(`stdout: ${stdout}`);
process.exit(0);
});
})();