From 932cfc3fbae942da6c1d54a5f4d459dfc065a9e6 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Thu, 16 Aug 2018 12:22:53 -0400 Subject: [PATCH] Fixing stripe import history. --- .../commands/reimport_stripe_history.py | 19 ++++++++++--------- apps/reader/views.py | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/profile/management/commands/reimport_stripe_history.py b/apps/profile/management/commands/reimport_stripe_history.py index 378d5b616..30757b74e 100644 --- a/apps/profile/management/commands/reimport_stripe_history.py +++ b/apps/profile/management/commands/reimport_stripe_history.py @@ -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 diff --git a/apps/reader/views.py b/apps/reader/views.py index 7fcb8674e..071982a16 100644 --- a/apps/reader/views.py +++ b/apps/reader/views.py @@ -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])