Merge branch 'master' of https://bitbucket.org/yackob03/quay
This commit is contained in:
commit
2d0a61b6c2
2 changed files with 21 additions and 5 deletions
|
@ -34,7 +34,7 @@ def process_basic_auth(auth):
|
||||||
if len(credentials) != 2:
|
if len(credentials) != 2:
|
||||||
logger.debug('Invalid basic auth credential format.')
|
logger.debug('Invalid basic auth credential format.')
|
||||||
|
|
||||||
if credentials[0] == '$token':
|
elif credentials[0] == '$token':
|
||||||
# Use as token auth
|
# Use as token auth
|
||||||
try:
|
try:
|
||||||
token = model.load_token_data(credentials[1])
|
token = model.load_token_data(credentials[1])
|
||||||
|
@ -77,7 +77,6 @@ def process_basic_auth(auth):
|
||||||
|
|
||||||
# We weren't able to authenticate via basic auth.
|
# We weren't able to authenticate via basic auth.
|
||||||
logger.debug('Basic auth present but could not be validated.')
|
logger.debug('Basic auth present but could not be validated.')
|
||||||
abort(401)
|
|
||||||
|
|
||||||
|
|
||||||
def process_token(auth):
|
def process_token(auth):
|
||||||
|
|
|
@ -1,19 +1,36 @@
|
||||||
from app import stripe
|
from app import stripe
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
EXCLUDE_CID = {'cus_2iVlmwz8CpHgOj'}
|
EXCLUDE_CID = {'cus_2iVlmwz8CpHgOj'}
|
||||||
|
|
||||||
offset = 0
|
offset = 0
|
||||||
total_monthly_revenue = 0
|
total_monthly_revenue = 0
|
||||||
|
|
||||||
|
def empty_tuple():
|
||||||
|
return (0, 0)
|
||||||
|
|
||||||
|
plan_revenue = defaultdict(empty_tuple)
|
||||||
|
|
||||||
batch = stripe.Customer.all(count=100, offset=offset)
|
batch = stripe.Customer.all(count=100, offset=offset)
|
||||||
while batch.data:
|
while batch.data:
|
||||||
for cust in batch.data:
|
for cust in batch.data:
|
||||||
if cust.id not in EXCLUDE_CID and cust.subscription:
|
if cust.id not in EXCLUDE_CID and cust.subscription:
|
||||||
sub = cust.subscription
|
sub = cust.subscription
|
||||||
total_monthly_revenue += sub.plan.amount * sub.quantity
|
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)
|
offset += len(batch.data)
|
||||||
batch = stripe.Customer.all(count=100, offset=offset)
|
batch = stripe.Customer.all(count=100, offset=offset)
|
||||||
|
|
||||||
dollars = total_monthly_revenue / 100
|
def format_money(total_cents):
|
||||||
cents = total_monthly_revenue % 100
|
dollars = total_cents / 100
|
||||||
print 'Monthly revenue: $%d.%02d' % (dollars, cents)
|
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)
|
||||||
|
|
Reference in a new issue