-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
540 additions
and
55,044 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ TENCENT_SECRETKEY= | |
# http://ai.youdao.com/gw.s | ||
YOUDAO_APPKEY= | ||
YOUDAO_KEY= | ||
|
||
# moji dict | ||
MOJI_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
const path = require('path') | ||
const fs = require('fs-extra') | ||
const axios = require('axios') | ||
const fglob = require('fast-glob') | ||
const cliProgress = require('cli-progress') | ||
const randomMua = require('random-mua') | ||
const argv = require('yargs').argv | ||
const env = require('dotenv').config({ | ||
path: path.join(__dirname, '../.env') | ||
}).parsed | ||
|
||
// download fixtures | ||
// --delete remove all fixtures | ||
|
||
if (argv.delete) { | ||
deletion() | ||
} else { | ||
main().catch(console.log) | ||
} | ||
|
||
async function main() { | ||
const proxyConfig = env.PROXY_HOST | ||
? { | ||
proxy: { | ||
host: env.PROXY_HOST, | ||
port: env.PROXY_PORT | ||
} | ||
} | ||
: {} | ||
if (env.PROXY_HOST) { | ||
console.log(`with proxy:${env.PROXY_HOST}:${env.PROXY_PORT}`) | ||
} | ||
|
||
const progressBars = new cliProgress.MultiBar({ | ||
format: ' {bar} | "{file}" | {value}/{total} | {status}', | ||
hideCursor: true, | ||
barCompleteChar: '\u2588', | ||
barIncompleteChar: '\u2591', | ||
clearOnComplete: false, | ||
stopOnComplete: true | ||
}) | ||
|
||
const errors = [] | ||
|
||
const fixturesPath = await fglob(['**/fixtures.js'], { | ||
cwd: path.join(__dirname, '../test'), | ||
absolute: true, | ||
onlyFiles: true | ||
}) | ||
|
||
await Promise.all(fixturesPath.map(fetchDictFixtures)) | ||
|
||
if (errors.length > 0) { | ||
console.log('\nErrors:\n\n', errors.map(([name]) => name).join('\n')) | ||
await fs.outputFile( | ||
path.join(__dirname, 'fixtures.log'), | ||
errors.map(([name, error]) => name + '\n' + error).join('\n\n') | ||
) | ||
} | ||
|
||
async function fetchDictFixtures(fixturePath) { | ||
const fixture = require(fixturePath) | ||
|
||
const fetched = [] | ||
|
||
for (const [filename, fetchUrl] of fixture.files) { | ||
const destPath = fixturePath.replace( | ||
/fixtures.js$/, | ||
`response/${filename}` | ||
) | ||
const stat = await fs.stat(destPath).catch(() => null) | ||
if (stat && stat.isFile()) { | ||
fetched.push(await fs.readFile(destPath, 'utf8')) | ||
continue | ||
} | ||
|
||
const dictname = /[\\/]+([^\\/]+)[\\/]+fixtures.js$/.exec(fixturePath)[1] | ||
|
||
const pgBar = progressBars.create(100, 0, { | ||
file: `${dictname}/${filename}`, | ||
status: 'downloading' | ||
}) | ||
|
||
try { | ||
var customConfig = | ||
typeof fetchUrl === 'string' | ||
? { | ||
url: fetchUrl | ||
} | ||
: fetchUrl(fetched) | ||
} catch (e) { | ||
pgBar.update(null, { status: 'parse error' }) | ||
pgBar.stop() | ||
continue | ||
} | ||
|
||
const { origin, host } = new URL(customConfig.url) | ||
|
||
if (!customConfig) { | ||
pgBar.update(null, { status: 'empty config' }) | ||
pgBar.stop() | ||
continue | ||
} | ||
|
||
const axiosConfig = { | ||
transformResponse: [data => data], | ||
...proxyConfig, | ||
...customConfig, | ||
headers: { | ||
'user-agent': randomMua(), | ||
...(customConfig.headers || {}) | ||
} | ||
} | ||
|
||
try { | ||
const { data: result } = await axios(axiosConfig).catch(e => | ||
e.response && e.response.status === 404 && e.response.data | ||
? e.response | ||
: axios({ | ||
...axiosConfig, | ||
headers: { | ||
...axiosConfig.headers, | ||
origin, | ||
host, | ||
referer: origin | ||
} | ||
}) | ||
) | ||
|
||
fetched.push(result) | ||
await fs.outputFile( | ||
fixturePath.replace(/fixtures.js$/, `response/${filename}`), | ||
result | ||
) | ||
|
||
pgBar.update(100, { status: 'success' }) | ||
pgBar.stop() | ||
} catch (e) { | ||
errors.push([`${dictname}/${filename}`, e]) | ||
|
||
pgBar.update(null, { status: 'failed' }) | ||
pgBar.stop() | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function deletion() { | ||
const fixturesPath = await fglob(['**/response'], { | ||
cwd: path.join(__dirname, '../test'), | ||
absolute: true, | ||
onlyDirectories: true | ||
}) | ||
|
||
fixturesPath.forEach(fixturePath => { | ||
fs.remove(fixturePath) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
files: [ | ||
['lex.html', 'https://cn.bing.com/dict/search?q=love'], | ||
[ | ||
'machine.html', | ||
`https://cn.bing.com/dict/search?q=${encodeURIComponent( | ||
'lose yourself in the dark' | ||
)}` | ||
], | ||
['related.html', 'https://cn.bing.com/dict/search?q=lovxx'] | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
test/specs/components/dictionaries/bing/response/machine.html
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
test/specs/components/dictionaries/bing/response/related.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
files: [ | ||
[ | ||
'catch-zht.html', | ||
'https://dictionary.cambridge.org/zhs/%E8%AF%8D%E5%85%B8/%E8%8B%B1%E8%AF%AD-%E6%B1%89%E8%AF%AD-%E7%B9%81%E4%BD%93/catch' | ||
], | ||
[ | ||
'house-zhs.html', | ||
'https://dictionary.cambridge.org/zhs/%E8%AF%8D%E5%85%B8/%E8%8B%B1%E8%AF%AD-%E6%B1%89%E8%AF%AD-%E7%AE%80%E4%BD%93/house' | ||
], | ||
[ | ||
'love.html', | ||
'https://dictionary.cambridge.org/zhs/%E8%AF%8D%E5%85%B8/%E8%8B%B1%E8%AF%AD-%E6%B1%89%E8%AF%AD-%E7%AE%80%E4%BD%93/love' | ||
] | ||
] | ||
} |
3,718 changes: 0 additions & 3,718 deletions
3,718
test/specs/components/dictionaries/cambridge/response/catch-zht.html
This file was deleted.
Oops, something went wrong.
3,277 changes: 0 additions & 3,277 deletions
3,277
test/specs/components/dictionaries/cambridge/response/house-zhs.html
This file was deleted.
Oops, something went wrong.
3,203 changes: 0 additions & 3,203 deletions
3,203
test/specs/components/dictionaries/cambridge/response/love.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
files: [ | ||
['love.html', 'http://dict.cnki.net/dict_result.aspx?searchword=love'] | ||
] | ||
} |
Oops, something went wrong.