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


class Command(BaseCommand):
    """
    python manage.py dump_20170322_export_activity_user
    """

    def handle(self, *args, **options):
        result_log = open('曾报名免费活动用户id.txt', 'a')
        error_log = open('曾报名免费活动用户id_error.txt', 'a')
        problems = Problem.objects.filter(activity_id__isnull=False, user__isnull=False)
        for problem in problems:
            try:
                result_log.write(u'{}\n'.format(problem.user_id))
                print problem.user_id
            except Exception as e:
                message = str(problem.id) + ':' + e.message
                print message
                error_log.write(message + '\n')
                import traceback;
                traceback.print_exc(error_log)
        print 'DONE!'
        result_log.close()
