-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.js
More file actions
64 lines (55 loc) · 2.5 KB
/
book.js
File metadata and controls
64 lines (55 loc) · 2.5 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
59
60
61
62
63
64
"use strict";
import path from "path";
import fs from "fs";
import * as tabletojsonPkg from "tabletojson";
const { Tabletojson } = tabletojsonPkg;
export class Book {
constructor(name, fetcher, asin = null) {
this.name = name;
this.fetch = fetcher;
this.asin = asin;
}
}
export class UkaruEigo extends Book {
constructor(name, id, asin = null) {
super(
name,
() =>
fs.promises
.readFile(this.jsonPath, "UTF8")
.then((file) => JSON.parse(file))
.catch((_e) => this.download()),
asin,
);
this.ukaruEigoId = id;
}
get jsonPath() {
return path.join(import.meta.dirname, ".cache", `${this.ukaruEigoId}.json`);
}
async download() {
const url = `https://ukaru-eigo.com/${this.ukaruEigoId}/`;
console.log(`${this.name}データを ${url} からダウンロード中...`);
const words = (await Tabletojson.convertUrl(url))[0].map((word) => ({
id: parseInt(word["No"] ?? word["No."] ?? word["番号"]),
en: (word["単語"] ?? word["英単語"] ?? word["熟語"] ?? "").trim(),
jp: (word["意味"] ?? "").trim(),
}));
await fs.promises.mkdir(path.dirname(this.jsonPath), { recursive: true });
await fs.promises.writeFile(this.jsonPath, JSON.stringify(words, null, 2) + "\n", "UTF8");
return words;
}
}
export const books = {
complete: new UkaruEigo("有名単語帳融合", "complete-word-list"),
systan: new UkaruEigo("システム英単語 (5訂版)", "systan-word-list", "4796111379"),
teppeki: new UkaruEigo("鉄壁 (改訂版)", "teppeki-word-list", "404604411X"),
leap2: new UkaruEigo("改訂版 必携英単語 LEAP", "leap-modified-list", "4410144235"),
leap: new UkaruEigo("(旧版) 必携英単語 LEAP", "leap-word-list", "4410144227"),
passtan: new UkaruEigo("英検準1級 でる順パス単 (5訂版)", "passtan-p1-word-list", "401094983X"),
tango_ou: new UkaruEigo("単語王 2202", "tango-ou-word-list", "404604411X"),
target1900: new UkaruEigo("英単語ターゲット 1900 (6訂版)", "target-1900-word-list", "4010346469"),
target1900_5: new UkaruEigo("英単語ターゲット 1900 (5訂版)", "target-1900-5th-word-list", "4010339179"),
target1400only: new UkaruEigo("英単語ターゲット not 1900 but 1400", "target-1400-only"),
target1400: new UkaruEigo("英単語ターゲット 1400 (5訂版)", "target-1400-word-list", "4010346477"),
jukugotarget: new UkaruEigo("英熟語ターゲット 1000 (5訂版)", "jukugo-target-1000-list", "4010346493"),
};