提交 8f8c9bf5 编写于 作者: W wizardforcel

2019-06-28 11:17:45

上级 75964221
// 需要 Image Magick 和 pngquant
/*
apt install imagemagick
apt install pngquant
*/
var chp = require('child_process')
var fs = require('fs')
var path = require('path')
var os = require('os')
function betterImg(img) {
function betterImg(img, tmpDir) {
var tmpDir = os.tmpdir()
tmpDir = tmpDir || os.tmpdir()
var fname = new Date().getTime().toString() + '.jpg'
fname = path.join(tmpDir, fname)
fs.writeFileSync(fname, img)
......
......@@ -46,7 +46,7 @@ function processImg(html, pageUrl, imgs) {
if(!imgs.has(picname)) {
var data = request('GET', url).getBody();
data = betterImg(data)
data = betterImg(data, 'tmp')
imgs.set(picname, data);
}
......@@ -89,6 +89,11 @@ function compToId(name) {
return id
}
function safeMkDir(dir) {
try {fs.mkdirSync(dir)}
catch(ex) {}
}
function main() {
var name = process.argv[2]
......@@ -98,6 +103,7 @@ function main() {
var toc = getToc(id)
var articles = []
var imgs = new Map()
safeMkDir('tmp')
for(var it of toc) {
var prefix = 'https://www.kaggle.com'
......@@ -123,6 +129,7 @@ function main() {
articles.splice(0, 0, {title: `Kaggle Kernel - ${name}`, content: ''})
genEpub(articles, imgs)
}
if(module == require.main) main()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册