Fixing stripe import history.

This commit is contained in:
Samuel Clay 2018-08-16 12:22:53 -04:00
parent e74dde6e30
commit 932cfc3fba
2 changed files with 11 additions and 10 deletions

View file

@ -2,18 +2,17 @@ import stripe, datetime, time
from django.conf import settings
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from optparse import make_option
from utils import log as logging
from apps.profile.models import Profile, PaymentHistory
from apps.profile.models import Profile
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
# make_option("-u", "--username", dest="username", nargs=1, help="Specify user id or username"),
# make_option("-e", "--email", dest="email", nargs=1, help="Specify email if it doesn't exist"),
make_option("-d", "--days", dest="days", nargs=1, type='int', default=365, help="Number of days to go back"),
make_option("-o", "--offset", dest="offset", nargs=1, type='int', default=0, help="Offset customer (in date DESC)"),
make_option("-s", "--start", dest="start", nargs=1, type='string', default=None, help="Offset customer_id (starting_after)"),
)
def handle(self, *args, **options):
@ -21,20 +20,22 @@ class Command(BaseCommand):
week = (datetime.datetime.now() - datetime.timedelta(days=int(options.get('days', 365)))).strftime('%s')
failed = []
limit = 100
offset = options.get('offset')
starting_after = options.get('start')
i = 0
while True:
logging.debug(" ---> At %s" % offset)
logging.debug(" ---> At %s / %s" % (i, starting_after))
i += 1
try:
data = stripe.Charge.all(created={'gt': week}, count=limit, offset=offset)
data = stripe.Charge.all(created={'gt': week}, count=limit, starting_after=starting_after)
except stripe.APIConnectionError:
time.sleep(10)
continue
charges = data['data']
if not len(charges):
logging.debug("At %s, finished" % offset)
logging.debug("At %s (%s), finished" % (i, starting_after))
break
offset += limit
starting_after = charges[-1]["id"]
customers = [c['customer'] for c in charges if 'customer' in c]
for customer in customers:
try:
@ -56,7 +57,7 @@ class Command(BaseCommand):
logging.debug(" ---> %s is fine" % user.username)
except stripe.APIConnectionError:
logging.debug(" ***> Failed: %s" % user.username)
failed.append(username)
failed.append(user.username)
time.sleep(2)
continue

View file

@ -1344,7 +1344,7 @@ def load_river_stories__redis(request):
starred_stories = MStarredStory.objects(
user_id=user.pk,
story_hash__in=story_hashes
).only('story_hash', 'starred_date')
).only('story_hash', 'starred_date', 'user_tags')
starred_stories = dict([(story.story_hash, dict(starred_date=story.starred_date,
user_tags=story.user_tags))
for story in starred_stories])