Skip to content

Instantly share code, notes, and snippets.

@charlycoste
Last active August 29, 2015 14:13
Show Gist options
  • Save charlycoste/19b0ec06d854d216584f to your computer and use it in GitHub Desktop.
Save charlycoste/19b0ec06d854d216584f to your computer and use it in GitHub Desktop.
Automatically download github bills with CasperJS
login = "<login>"
password = "<password>"
directory = "<directory>"
organization = "<organization>"
casper = require('casper').create
verbose: true
logLevel: "debug"
getLinks = ->
links = document.querySelectorAll ".payment-history tr.succeeded"
Array::map.call links, (e) ->
id: e.querySelector('.id code').textContent.trim()
href: e.querySelector('.receipt a').getAttribute('href')
date: e.querySelector('.date time').getAttribute('title').split(' ').shift()
casper.start "https://github.com/organizations/#{organization}/settings/billing", ->
@fill '[action="/session"]',
login: login
password: password,
true
casper.then ->
@each @evaluate(getLinks), (self, link) ->
# Ex: myfolder/2014-12-01_AAE8EAI.pdf
@download link.href, "#{directory}/#{link.date}_#{link.id}.pdf"
casper.run()
login = "<login>"
password = "<password>"
directory = "<directory>"
casper = require('casper').create
verbose: true
logLevel: "debug"
getLinks = ->
links = document.querySelectorAll "a[href^='/profile/billing/invoices/']"
Array::map.call links, (e) ->
id: e.textContent.trim()
href: e.getAttribute('href')
casper.start "https://scrutinizer-ci.com/profile/billing", ->
@fill '[action="/login_check"]',
"user_login[email]": login
"user_login[password]": password,
true
casper.then ->
@capture "login.png"
@each @evaluate(getLinks), (self, link) ->
# Ex: myfolder/AAE8EAI.pdf
@download link.href, "#{directory}/#{link.id}.pdf"
casper.run()
@charlycoste
Copy link
Author

Launch it with casperjs --ssl-protocol=any download_github_bills.coffee to avoid PhantomJS problem with SSLv3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment