Created
January 3, 2014 19:31
-
-
Save JimmyHoffa/8244850 to your computer and use it in GitHub Desktop.
Simpler stuff..
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
// Make sure we got a filename on the command line. | |
if (process.argv.length < 3) { | |
console.log('Usage: node ' + process.argv[1] + ' FILENAME'); | |
process.exit(1); | |
} | |
// Read the file and print its contents. | |
var fs = require('fs') | |
, filename = process.argv[2] | |
, happy = ""; | |
fs.readFile(filename, 'utf8', function(err, data) { | |
if (err) throw err; | |
console.log('[SO-ChatBot-Driver] OK: ' + filename); | |
//console.log(data) | |
happy = data; | |
}); | |
var http = require("http"); | |
var Browser = require("zombie"); | |
var assert = require("assert"); | |
console.log("[SO-ChatBot-Driver] zombie and assert loaded"); | |
var chatURL = "http://chat.stackexchange.com/rooms/118/root-access"; | |
var browser = new Browser({ debug: true, maxWait: 30000, waitFor: 30000, userAgent: "Mozilla/5.0 (Windows NT 6.2; Win64; x64;) Gecko/20100101 Firefox/20.0" }); | |
var browserVisitHandler = function() { | |
console.log('[SO-ChatBot-Driver] 0n page ' + browser.location); | |
console.warn('[SO-ChatBot-Driver] ' + browser.document.innerHTML); console.warn('[SO-ChatBot-Driver] blah'); | |
var affildoc = browser.document; | |
var emailField = affildoc.getElementById("email"); | |
emailField.value = "RAR!"; | |
var passwordField = affildoc.getElementById("password"); | |
passwordField.value = "ARRRR"; | |
browser.pressButton(".affiliate-button", function() { | |
console.log('[SO-ChatBot-Driver] On page ' + browser.location); | |
}); | |
}; | |
var postResponseHandler = function(res) { | |
console.log(res); | |
res.setEncoding('utf8'); | |
res.on('data', function(signinFormUrl) { | |
console.log('[SO-ChatBot-Driver] ' + (signinFormUrl || 'No URL ???')); | |
if (!signinFormUrl ) return; | |
browser.visit(signinFormUrl, browserVisitHandler); | |
}); | |
}; | |
var postData = "from=" + chatURL; | |
var postRequest = http.request( | |
{ | |
host: 'stackexchange.com', | |
port: 80, | |
path: '/users/signin', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Content-Length': postData.length | |
} | |
}, | |
postResponseHandler); | |
console.log('[SO-ChatBot-Driver] Writing postData:' + postData); | |
postRequest.write(postData); | |
console.log('[SO-ChatBot-Driver] Ending request.'); | |
postRequest.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment