def update_activities(): print 'Update activities' total = 0 for activity in models.Activity.objects.filter(creation__gte=datetime.datetime(2016, 07, 4, 0, 0, 0, 0, pytz.UTC), message_type__in=[0, 1]).select_related('ownedcard', 'ownedcard__card', 'account'): if '/' in activity.right_picture: # not imgur activity.right_picture = ownedcardimageurl({}, activity.ownedcard, card=activity.ownedcard.card, english_version=(activity.account.language != 'JP')) activity.save() total += 1
def update_activities(): print 'Update activities' total = 0 for activity in models.Activity.objects.filter( creation__gte=datetime.datetime(2016, 07, 4, 0, 0, 0, 0, pytz.UTC), message_type__in=[0, 1]).select_related('ownedcard', 'ownedcard__card', 'account'): if '/' in activity.right_picture: # not imgur activity.right_picture = ownedcardimageurl( {}, activity.ownedcard, card=activity.ownedcard.card, english_version=(activity.account.language != 'JP')) activity.save() total += 1
def handle(self, *args, **options): print 'Delete activities max bonded/max leveled...' while models.Activity.objects.filter(Q(message='Max Leveled a card') | Q(message='Max Bonded a card')).count(): ids = list(models.Activity.objects.filter(Q(message='Max Leveled a card') | Q(message='Max Bonded a card')).values_list('pk', flat=True)[:100]) total_this = models.Activity.objects.filter(pk__in=ids).delete() print 'Done.' print 'Delete activities rank in event without ranking...' while get_rankevent_withoutranking_queryset().count(): ids = list(get_rankevent_withoutranking_queryset().values_list('pk', flat=True)[:100]) total_this = get_rankevent_withoutranking_queryset().filter(pk__in=ids).delete() print 'Done.' print 'Cache for owned cards activities' while get_ownedcardqueryset().count(): activities_ownedcards = get_ownedcardqueryset()[:500] for activity in activities_ownedcards: account = activity.ownedcard.owner_account # Fix account activity.account = account # Cache activity = activity_cache_account(activity, account) activity.message_data = concat_args(unicode(activity.ownedcard.card), activity.ownedcard.stored) activity.right_picture_link = '/cards/' + str(activity.ownedcard.card.id) + '/' activity.right_picture = ownedcardimageurl({}, activity.ownedcard) activity.save() print '.', sys.stdout.flush() print 'Done.' print 'Cache for rank up activities' while get_rankupqueryset().count(): activities_rankup = get_rankupqueryset()[:500] for activity in activities_rankup: # Cache activity = activity_cache_account(activity, activity.account) activity.message_data = concat_args(activity.number) activity.save() print '.', sys.stdout.flush() print 'Done.' print 'Cache for Rank in event activities' while get_rankeventqueryset().count(): activities_rankevent = get_rankeventqueryset()[:500] for activity in activities_rankevent: # Cache activity = activity_cache_account(activity, activity.account) activity.message_data = concat_args(activity.eventparticipation.ranking, unicode(activity.eventparticipation.event)) activity.right_picture = eventimageurl({}, activity.eventparticipation.event, english=(activity.account.language != 'JP')) activity.right_picture_link = '/events/' + activity.eventparticipation.event.japanese_name + '/' activity.save() print '.', sys.stdout.flush() print 'Done.' print 'Remove duplicate activities with ownedcards' lastSeenId = float('-Inf') i = 0 total_deleted = 0 while get_duplicateownedcard_queryset()[i:i+500].count(): activities_ownedcards = get_duplicateownedcard_queryset()[i:i+500] for activity in activities_ownedcards: if activity.ownedcard_id == lastSeenId: print 'delete', activity activity.delete() total_deleted += 1 else: lastSeenId = activity.ownedcard_id pass i += 500 print '.', sys.stdout.flush() print 'Done.'
def handle(self, *args, **options): print 'Delete activities max bonded/max leveled...' while models.Activity.objects.filter(Q(message='Max Leveled a card') | Q(message='Max Bonded a card')).count(): ids = list(models.Activity.objects.filter(Q(message='Max Leveled a card') | Q(message='Max Bonded a card')).values_list('pk', flat=True)[:100]) total_this = models.Activity.objects.filter(pk__in=ids).delete() print 'Done.' print 'Delete activities rank in event without ranking...' while get_rankevent_withoutranking_queryset().count(): ids = list(get_rankevent_withoutranking_queryset().values_list('pk', flat=True)[:100]) total_this = get_rankevent_withoutranking_queryset().filter(pk__in=ids).delete() print 'Done.' print 'Cache for owned cards activities' while get_ownedcardqueryset().count(): activities_ownedcards = get_ownedcardqueryset()[:500] for activity in activities_ownedcards: account = activity.ownedcard.owner_account # Fix account activity.account = account # Cache activity = activity_cache_account(activity, account) activity.message_data = concat_args(unicode(activity.ownedcard.card), activity.ownedcard.stored) activity.right_picture_link = singlecardurl(activity.ownedcard.card) activity.right_picture = ownedcardimageurl({}, activity.ownedcard) activity.save() print '.', sys.stdout.flush() print 'Done.' print 'Cache for rank up activities' while get_rankupqueryset().count(): activities_rankup = get_rankupqueryset()[:500] for activity in activities_rankup: # Cache activity = activity_cache_account(activity, activity.account) activity.message_data = concat_args(activity.number) activity.save() print '.', sys.stdout.flush() print 'Done.' print 'Cache for Rank in event activities' while get_rankeventqueryset().count(): activities_rankevent = get_rankeventqueryset()[:500] for activity in activities_rankevent: # Cache activity = activity_cache_account(activity, activity.account) activity.message_data = concat_args(activity.eventparticipation.ranking, unicode(activity.eventparticipation.event)) activity.right_picture = eventimageurl({}, activity.eventparticipation.event, english=(activity.account.language != 'JP')) activity.right_picture_link = '/events/' + activity.eventparticipation.event.japanese_name + '/' activity.save() print '.', sys.stdout.flush() print 'Done.' print 'Remove duplicate activities with ownedcards' lastSeenId = float('-Inf') i = 0 total_deleted = 0 while get_duplicateownedcard_queryset()[i:i+500].count(): activities_ownedcards = get_duplicateownedcard_queryset()[i:i+500] for activity in activities_ownedcards: if activity.ownedcard_id == lastSeenId: print 'delete', activity activity.delete() total_deleted += 1 else: lastSeenId = activity.ownedcard_id pass i += 500 print '.', sys.stdout.flush() print 'Done.'