-
-
Save MadaraUchiha/8328e8204f85466b7b7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var cheerio = require('cheerio'); | |
var Promise = require("bluebird"); | |
var request = Promise.promisifyAll(require('request')); | |
var WebSocket = require('ws'); | |
var email = "SE email", | |
password = "SE pw", | |
roomid = 17; | |
var j = request.jar() | |
request.getAsync({url:"https://stackoverflow.com/users/login", jar:j}).then(function(response){ | |
var $ = cheerio.load(response[0].body) | |
var fkey = $("input[name=fkey]").attr('value') | |
return request.postAsync({url:"https://stackoverflow.com/users/login", form: {email:email,password:password,fkey:fkey}, jar:j}) | |
}).then(function(response){ | |
return request.getAsync({url:"http://chat.stackoverflow.com/rooms/"+roomid, jar:j}) | |
}).then(function(response){ | |
var $ = cheerio.load(response[0].body) | |
var fkey = $("input[name=fkey]").attr('value') | |
var url, time; | |
request.postAsync({url:"http://chat.stackoverflow.com/ws-auth",form:{fkey:fkey,roomid:roomid}, jar:j}).then(function(response){ | |
url=JSON.parse(response[0].body).url | |
return request.postAsync({url:"http://chat.stackoverflow.com/chats/"+roomid+"/events", form:{fkey:fkey}, jar:j}) | |
}).then(function(response){ | |
time=JSON.parse(response[0].body).time | |
// j.getCookies, j.getCookieString are not fucking working https://github.com/request/request#examples | |
/* | |
Cookie: __qca=P0-836267970-1427913531157; | |
__utma=27693923.873887550.1427913531.1427913531.1427913531.1; | |
__utmz=27693923.1427913531.1.1.utmcsr=chat.stackexchange.com|utmccn=(referral)|utmcmd=referral|utmcct=/login/global; | |
_ga=GA1.2.873887550.1427913531; | |
acct=t=jL8DaExcfCTwfaQgrJ03tZ0gr3KvPY88&s=9B6qYhv3swjfrB5hD%2fXm0BLEDbnilw9V*/ | |
console.log(url+"?l="+time) | |
var ws = new WebSocket(url+"?l="+time, null, {headers:{ | |
'Origin': 'http://chat.stackoverflow.com'/*, | |
'Cookie': j._jar.store.idx['stackoverflow.com']['/']['acct'].value*/ | |
}}); | |
ws.on('message', function(message) { | |
console.log('received: %s', message); | |
}); | |
ws.on('open', function() { | |
console.log('opened') | |
}); | |
ws.on('error', function(e) { | |
console.log(e) | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment