forked from llt22/coca-vocabulary-20000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 1.6 KB
/
index.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
const XLSX = require("xlsx");
const fs = require('fs')
let count = 0
let part = 0
let fileName
let writeStream
function PrefixZero(num, n) {
return (Array(n).join(0) + num).slice(-n);
}
fs.readdir('excel', (err, files) => {
files.forEach(file => {
console.log(`excel/${file}`)
const workbook = XLSX.readFile(`excel/${file}`)
const sheetName = workbook.SheetNames[0]
const worksheet = workbook.Sheets[sheetName]
const items = XLSX.utils.sheet_to_json(worksheet, { header: 1 })
items.forEach((item) => {
const word = item[0]
const phonetic = item[1]
const paraphrase = item[2]
if (count % 200 === 0) {
part += 1
fileName = `vocabulary/part${PrefixZero(part, 3)}_${count + 1}-${count + 200}.md`
writeStream = fs.createWriteStream(fileName, {
flags: 'a' // 'a' means appending (old data will be preserved)
})
}
const r_word = `${count + 1} ${word} \r\n`
const r_phonetic = `- ${phonetic} \r\n`
const r_paraphrase = `- ${paraphrase} \r\n`
const r_d_ren = `- [人人词典](https://www.91dict.com/words?w=${word}) `
const r_d_ke = `[柯林斯](https://www.collinsdictionary.com/zh/dictionary/english/${word}) `
const r_d_lan = `[朗文](https://www.ldoceonline.com/dictionary/${word}) `
const end = '\r\n\r\n'
writeStream.write(r_word + r_phonetic + r_paraphrase + r_d_ren + r_d_ke + r_d_lan + end)
count++
})
});
});