Skip to content

Instantly share code, notes, and snippets.

@zbyte64
Created September 5, 2013 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbyte64/6453850 to your computer and use it in GitHub Desktop.
Save zbyte64/6453850 to your computer and use it in GitHub Desktop.
Cleans up test accounts
from gevent import monkey; monkey.patch_all()
from gevent.pool import Pool
import stripe
to_delete = list()
pool = Pool(10)
def check_customer(customer):
if customer['subscription'] or customer['default_card']:
return False
if customer['email'] in ['admin@montagable.com', 'user@example.com', 'admin@example.com', 'joe@example.com']:
return True
return False
def check_page(offset, count):
response = stripe.Customer.all(offset=offset, count=count)
for customer in response['data']:
if check_customer(customer):
to_delete.append(customer)
def remove(customer):
customer.delete()
count = 100
response = stripe.Customer.all(count=count)
total = response['count']
for customer in response['data']:
if check_customer(customer):
to_delete.append(customer)
for offset in range(count, total, count):
pool.apply_async(check_page, args=[offset, count])
pool.join()
pool.map_async(remove, to_delete).join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment