-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
29 lines (22 loc) · 849 Bytes
/
main.js
File metadata and controls
29 lines (22 loc) · 849 Bytes
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
'use strict';
const fs = require('fs');
const path = require('path');
const dateFormat = require('./util/dateFormat');
const getHTML = require('./util/getHTML');
const wFile = require('./util/wFile');
function getName(str) {
let name = str.replace(/https?:\/\//i, '').replace(/[\/\\:*?"'|<>]/g, '_').replace(/\.html?$/i, '') + '.html';
let time = dateFormat(new Date(), 'yyyy_MM_dd_hh_mm_ss_');
return time + name;
}
if (!fs.existsSync('cache')) {
fs.mkdirSync('cache');
}
function fetchHTML(url, name) {
getHTML(url).then((data) => {
wFile(path.join(__dirname, 'cache', name || getName(url)), data);
});
}
fetchHTML('http://www.chessgames.com/perl/gamesoftheday')
// fetchHTML('https://github.com/xovel/diary/blob/master/2018/01/2018-01-15-node-demo.md');
// fetchHTML('http://www.chessgames.com/perl/chessgame?gid=1151935')