Created
September 5, 2013 18:07
-
-
Save zbyte64/6453850 to your computer and use it in GitHub Desktop.
Cleans up test accounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ['[email protected]', '[email protected]', '[email protected]', '[email protected]']: | |
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