from stripe_payment.models import StripeSource, StripeCustomer
from django.core.management import BaseCommand
import crayons
from progressbar import ProgressBar


class Command(BaseCommand):
    help = 'Find stripe users without stripe card fingerprint in the database'

    def handle(self, *args, **options):
        customers = StripeCustomer.objects.all()
        progress = ProgressBar(max_value=StripeCustomer.objects.count())
        without = set()
        done = 0
        for customer in customers:
            if customer.sources.count() == 0:
                without.add(customer.pk)
            progress.update(done)
            done += 1
        print('=========================================================================')
        print("There are {} people without the details".format(len(without)))
        print('=========================================================================')
        print(crayons.red(without))
        print('=========================================================================')
