From 5088114ed70c22846e41a74f195d7ac7e2f86f38 Mon Sep 17 00:00:00 2001 From: yackob03 Date: Wed, 18 Dec 2013 21:02:06 -0500 Subject: [PATCH] Add a breakdown by plan type to the revenue tool. --- tools/monthlyrevenue.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/monthlyrevenue.py b/tools/monthlyrevenue.py index 9472eeda6..52fc8bff6 100644 --- a/tools/monthlyrevenue.py +++ b/tools/monthlyrevenue.py @@ -1,19 +1,36 @@ from app import stripe +from collections import defaultdict EXCLUDE_CID = {'cus_2iVlmwz8CpHgOj'} offset = 0 total_monthly_revenue = 0 +def empty_tuple(): + return (0, 0) + +plan_revenue = defaultdict(empty_tuple) + batch = stripe.Customer.all(count=100, offset=offset) while batch.data: for cust in batch.data: if cust.id not in EXCLUDE_CID and cust.subscription: sub = cust.subscription total_monthly_revenue += sub.plan.amount * sub.quantity + subscribers, revenue = plan_revenue[sub.plan.id] + plan_revenue[sub.plan.id] = (subscribers + 1, + revenue + sub.plan.amount * sub.quantity) offset += len(batch.data) batch = stripe.Customer.all(count=100, offset=offset) -dollars = total_monthly_revenue / 100 -cents = total_monthly_revenue % 100 -print 'Monthly revenue: $%d.%02d' % (dollars, cents) +def format_money(total_cents): + dollars = total_cents / 100 + cents = total_cents % 100 + return dollars, cents + +for plan_id, (subs, rev) in plan_revenue.items(): + d, c = format_money(rev) + print '%s: $%d.%02d(%s)' % (plan_id, d, c, subs) + +d, c = format_money(total_monthly_revenue) +print 'Monthly revenue: $%d.%02d' % (d, c)