# coding: utf-8
from __future__ import absolute_import, unicode_literals, print_function

from django.core.management import BaseCommand

from api.models.others import SearchKeyword

data =[
    {'keyword': u'双眼皮', 'rank': 1},
    {'keyword': u'瘦脸针', 'rank': 2},
    {'keyword': u'自体脂肪面部填充', 'rank': 3},
    {'keyword': u'玻尿酸', 'rank': 4},
    {'keyword': u'鼻综合', 'rank': 5},
    {'keyword': u'牙齿矫正', 'rank': 6},
    {'keyword': u'吸脂', 'rank': 7},
    {'keyword': u'下巴', 'rank': 8},
    {'keyword': u'埋线', 'rank': 9},
    {'keyword': u'美白嫩肤', 'rank': 10},
    {'keyword': u'超声刀', 'rank': 11},
    {'keyword': u'近视矫正', 'rank': 12},
    {'keyword': u'发际线', 'rank': 13},
    {'keyword': u'脱毛',  'rank': 14},
    {'keyword': u'自体脂肪隆胸',  'rank': 15},
    {'keyword': u'水光针', 'rank': 16},
    {'keyword': u'微整', 'rank': 17},
    {'keyword': u'瘦腿针',  'rank': 18},
    {'keyword': u'抗衰',  'rank': 19},
    {'keyword': u'半永久',  'rank': 20},
    {'keyword': u'假体隆胸',  'rank': 21},
]


class Command(BaseCommand):
    def handle(self, *args, **options):
        SearchKeyword.objects.update(is_online=False)
        for item in data:
            if SearchKeyword.objects.filter(keyword=item['keyword']):
                searchkeyword = SearchKeyword.objects.get(keyword=item['keyword'])
            else:
                searchkeyword = SearchKeyword()
                searchkeyword.keyword = item['keyword']
            searchkeyword.rank = item['rank']
            searchkeyword.is_online = True
            searchkeyword.save()
            print(item['keyword'])

        print('success')