Created
May 29, 2018 03:52
-
-
Save ishiduca/741e59758232c215023e024d371557d2 to your computer and use it in GitHub Desktop.
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
'use strict' | |
const fs = require('fs') | |
const path = require('path') | |
const request = require('hyperquest') | |
const {pipe, through} = require('mississippi') | |
const input = path.join(__dirname, 'feeds/feed.txt') | |
const output = path.join(__dirname, 'feeds/feed-filtered.txt') | |
const headers = {'user-agent': 'feedr'} | |
var buf = '' | |
pipe( | |
fs.createReadStream(input), | |
through.obj(function (d, _, done) { | |
var s = String(d) | |
var lines = s.split('\n') | |
var last = lines.pop() | |
if (buf) lines[0] = buf + lines[0] | |
lines.forEach(line => this.push(line)) | |
buf = last | |
done() | |
}, function (done) { | |
if (buf) this.push(buf) | |
done() | |
}), | |
through.obj((d, _, done) => { | |
done(null, String(d).split('\t')) | |
}), | |
through.obj((data, _, done) => { | |
request(data[0], {headers}, (err, res) => { | |
if (res && res.statusCode === 200) { | |
done(null, data.join('\t') + '\n') | |
} else { | |
if (err) console.error(err) | |
else console.error(`statusError: ${res.statusCode} ... ${data[0]}`) | |
done() | |
} | |
}) | |
}), | |
fs.createWriteStream(output), | |
err => err ? console.error(err) : console.log('!!FINISHED!!') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment