# coding:utf-8
from __future__ import unicode_literals

import os
import tablib
import random
from datetime import datetime
from django.core.management import BaseCommand
from django.db import transaction
from django.db import connection
from api.models import UserExtra
from gm_types.gaia import LOGIN_AUTH_TYPE
from gm_types.gaia import PLATFORM_CHANNEL
from api.tool.person import create_person_by_phone


import requests
# 使用方式 python manage.py update_fake_user
class Command(BaseCommand):

    def handle(self, *args, **options):
        print('start....')
        uids = requests.get('http://dev.c.xxapi.cn/v1/auth/uids').json()
        cursor = connection.cursor()
        for uid in uids:

            try:
                sql = "select username from auth_user where id={0}".format(uid)
                print cursor.execute(sql),sql

                res = cursor.fetchone()

                if isinstance(res,tuple):
                    sql2 = 'UPDATE auth_user SET last_name="{0}" WHERE id={1}'.format(res[0], uid)

                    print cursor.execute(sql2),sql2
            except Exception as e:
                print e


        print('update finish ....')

