Jake.codes

Starbucks Card Balance, for Pythonista

Sunday, May 05, 2013

# -*- coding: utf-8 -*-
# Starbucks API by Jake Bilbrey
#
# You can remember your username
# and or password by setting the
# blank variables in the code.
#
# Not secure, but usable.
# More about it can be found at
# http://emeraldsiren.com
import console
import requests

username = ""
password = ""

console.clear()

try: 
    if username.__len__() < 1 or password.__len__() < 1:
        input = console.login_alert("Log in to Starbucks","Sent in plain text, but not stored",username,password)
        username = input[0]
        password = input[1]

    print "Loading…"

    starbucks = requests.get('http://emeraldsiren.com/' + username + '/' + password)
    transactions = starbucks.json['transactions']
    console.clear()
    print "Your Starbucks Card\n"
    print "Balance: %s" % (starbucks.json['balance'])
    print "Stars: %d" % (starbucks.json['stars'])
    print "Rewards: %d\n" % (starbucks.json['rewards'])
    print "Recent Transactions:"
    for transaction in reversed(transactions):
        print "%s $%s %s" % (transaction['date'], transaction['amount'], transaction['type'])

except:
    console.clear()