Skip to content

Instantly share code, notes, and snippets.

@jhs
Created May 25, 2012 10:39
Show Gist options
  • Save jhs/2787238 to your computer and use it in GitHub Desktop.
Save jhs/2787238 to your computer and use it in GitHub Desktop.
Get irccloud backlog
var request = require('request')
var SINCE = +process.env.since
if(!SINCE)
throw new Error('Need $since')
get_lines(SINCE)
function get_lines(beforeid) {
var headers = { 'Cookie': process.env.cookie }
if(!headers.Cookie)
throw new Error('Need $cookie')
var url = "https://irccloud.com/chat/backlog?bid=71591&cid=6491&num=1000&beforeid=" + beforeid
console.log('Fetching: %s', url)
request({'url':url, 'headers':headers, 'json':true}, function(er, res) {
if(er) throw er
if(!Array.isArray(res.body))
throw new Error('Bad body: ' + res.body)
var first_id = res.body[0].eid
console.log('Got %d up to %d', res.body.length, first_id)
var highlights = res.body.reverse().filter(function(M) { return M.highlight })
if(highlights.length) {
console.log('')
highlights.forEach(function(M) {
if(! process.env.dir)
console.log('>>> %d <<< %s', M.eid, M.msg || M.eid)
else
console.dir(M)
})
console.log('')
}
get_lines(first_id)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment