# coding=utf-8
from django.core.management import BaseCommand

from api.models import Order


class Command(BaseCommand):

    def handle(self, *args, **options):
        f = open('/tmp/phone_crypt.txt', 'w')
        orders = Order.objects.all()
        cnt = orders.count()
        bgn = 0
        step = 1000
        while bgn <= cnt:
            print bgn
            for o in orders[bgn: bgn+step]:
                if o.phone is not None:
                    f.write('%s\n' % (o.id))
                    o.phone_crypt = o.phone
                    o.save()
            bgn += step
