<commit_before>from django.core.management.base import BaseCommand, CommandError
from Running.models import User, Run
import requests
import datetime
import json
import time
import stripe
from django.conf import settings
stripe.api_key = settings.STRIPE_SECRET_KEY


class Command(BaseCommand):
    help = 'Charges all customers who have registered with stripe'


    def handle(self, *args, **options):
        users_with_customers = User.objects.exclude(stripe_customer_id=None)
        amount_to_pay = 0
        for user in users_with_customers:
            for sponsorship in user.sponsorships_given.all():
                if sponsorship.left_to_pay > 0:
                    amount_to_pay = amount_to_pay + sponsorship.left_to_pay
                    print amount_to_pay
            for wager in user.wagers_given.filter(paid=False, fulfilled=True):
                amount_to_pay = amount_to_pay + wager.amount
                print amount_to_pay
            print amount_to_pay
            if amount_to_pay!=0:
                stripe_status = stripe.Charge.create(
                    amount=int(amount_to_pay*100),
                    currency="dkk",
                    customer=user.stripe_customer_id
                )["status"] 
                if stripe_status == "succeeded":
                    for sponsorship in user.sponsorships_given.all():
                        sponsorship.amount_paid = sponsorship.total_amount
                        sponsorship.save()
                    for wager in user.wagers_given.filter(paid=False, fulfilled=True):
                        wager.paid = True
                        wager.save()


                print "{0} charged {1}".format(user.username, amount_to_pay)<commit_msg>[Changes] charge to only work on the first of the month.<commit_after>from django.core.management.base import BaseCommand, CommandError
from Running.models import User, Run
import requests
import datetime
import json
import time
import stripe
from django.conf import settings
stripe.api_key = settings.STRIPE_SECRET_KEY


class Command(BaseCommand):
    help = 'Charges all customers who have registered with stripe'


    def handle(self, *args, **options):
        if datetime.datetime.today().day == 1:

            users_with_customers = User.objects.exclude(stripe_customer_id=None)
            amount_to_pay = 0
            for user in users_with_customers:
                for sponsorship in user.sponsorships_given.all():
                    if sponsorship.left_to_pay > 0:
                        amount_to_pay = amount_to_pay + sponsorship.left_to_pay
                        print amount_to_pay
                for wager in user.wagers_given.filter(paid=False, fulfilled=True):
                    amount_to_pay = amount_to_pay + wager.amount
                    print amount_to_pay
                print amount_to_pay
                if amount_to_pay!=0:
                    stripe_status = stripe.Charge.create(
                        amount=int(amount_to_pay*100),
                        currency="dkk",
                        customer=user.stripe_customer_id
                    )["status"] 
                    if stripe_status == "succeeded":
                        for sponsorship in user.sponsorships_given.all():
                            sponsorship.amount_paid = sponsorship.total_amount
                            sponsorship.save()
                        for wager in user.wagers_given.filter(paid=False, fulfilled=True):
                            wager.paid = True
                            wager.save()


                    print "{0} charged {1}".format(user.username, amount_to_pay)
{'fraction_non_alphanumeric': 0.06867305061559507, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 1.834108527131783, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '113153', 'n_tokens_mistral': 1009, 'n_tokens_neox': 905, 'n_words': 220}