Last active
December 28, 2016 07:40
-
-
Save cjoshmartin/07b10a64480d31c6fb9ce74ed080ba72 to your computer and use it in GitHub Desktop.
gets current paycheck amount
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
//require to install: Casperjs, nodejs and phatomjs | |
// need to create a config file as well | |
//gets paycheck information for IU Staff | |
var casper = require('casper').create(); | |
var xpath = require("casper").selectXPath; | |
var config = require('../config.json'); | |
var fs =require('fs'); | |
var pay; | |
var date; | |
var current ={"paycheck":{}}; | |
casper.start(config.money.paycheck.url,function () { | |
this.wait(1000,function () { | |
this.echo('filling form...'); | |
this.sendKeys('#username',config.cas.username); | |
this.sendKeys('#password',config.cas.password); | |
this.click('input[name="_eventId_submit"]') | |
this.wait(3000,function () { | |
date = (this.fetchText(xpath('//table[9]/tbody/tr/td'))).trim(); | |
date = date.substring(0,10); | |
// this.echo("the date of pay: "+date); | |
current.paycheck.date=date; | |
// this.echo("current.date = "+current.date); | |
pay = (this.fetchText(xpath('//tr[6]/td'))).trim(); | |
pay = pay.substring(1,7); | |
// this.echo("current balance: " + pay); | |
current.paycheck.pay =parseFloat(pay); | |
// this.echo("current.pay = " + current.pay); | |
console.log("output: " + JSON.stringify(current,null,' ')); | |
fs.write('data.json',JSON.stringify(current,null,' '),'w'); | |
}); | |
}); | |
}); | |
casper.on("page.error", function(msg, trace) { | |
this.echo("Error: " + msg, "ERROR"); | |
this.echo("file: " + trace[0].file, "WARNING"); | |
this.echo("line: " + trace[0].line, "WARNING"); | |
this.echo("function: " + trace[0]["function"], "WARNING"); | |
errors.push(msg); | |
}); | |
casper.run(function() { | |
if (errors.length > 0) { | |
this.echo(errors.length + ' Javascript errors found', "WARNING"); | |
} else { | |
this.echo(errors.length + ' Javascript errors found', "INFO"); | |
} | |
casper.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment