Create a gist now

Instantly share code, notes, and snippets.

Get amazon remaining grant credits... scraping an AWS site
"""
Fetches the remaining EDU grant credits in an Amazon account using scraping
with Python's RoboBrowser (perl's WWW::Mechanize look-alike)
"""
from robobrowser import RoboBrowser
credits_url = 'https://portal.aws.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=credits'
browser = RoboBrowser(history=True)
browser.open(credits_url)
form = browser.get_form()
# Sorry, no proper credentials security until Amazon exposes this attribute
# as a proper API call (perhaps via CloudWatch Billing?)
form['email'].value = '<AWS_USERNAME>'
form['password'].value = '<AWS_PASSWORD>'
browser.submit_form(form)
for field in browser.response.text.split('\n'):
if 'Credits Balance' in field:
print field.split('$')[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment