Created
May 8, 2018 08:38
-
-
Save LeoDJ/1d797ac0ca01edfcce9f11d5cf3d9a7b to your computer and use it in GitHub Desktop.
ISDT firmware download script
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
const cheerio = require('cheerio') | |
const request = require('request') | |
const fs = require('fs'); | |
let subfolder = 'firmwares' | |
if(!fs.existsSync(subfolder)) | |
fs.mkdirSync(subfolder); | |
consoleLog = console.log | |
console.log = (text) => { | |
consoleLog(text) | |
fs.appendFileSync('dl.log', text + '\n') | |
} | |
function scrape(html) { | |
const $ = cheerio.load(html) | |
let hrefs = $('a', '.panel').has('button').map((i, elem) => elem.attribs.href).get() | |
hrefs = hrefs.filter(el => el.indexOf('.zip') > -1 && el.indexOf('V') > -1) //filter all firmware downloads | |
hrefs.forEach(link => { | |
name = link.split('/').slice(-1)[0] | |
folder = subfolder + '/' | |
folder += name.split('V')[0].slice(0, -1) | |
path = folder + '/' + name | |
if(!fs.existsSync(folder)) { | |
fs.mkdirSync(folder); | |
} | |
if(!fs.existsSync(path)) { | |
console.log(new Date().toISOString() + ' - downloading new file: ' + path) | |
request(link).pipe(fs.createWriteStream(path)) | |
} | |
}) | |
} | |
request('http://www.isdt.co/download', (err, res, html) => { | |
scrape(html) | |
}); | |
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
{ | |
"dependencies": { | |
"cheerio": "^1.0.0-rc.2", | |
"request": "^2.85.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment