#! /usr/bin/env python
# -*- coding: utf-8 -*-
# create by oldman
# Date: 2018/10/11
from django.core.management import BaseCommand

from hippo.models import Merchant
from hippo.models import MerchantNonsync


class Command(BaseCommand):
    """
    同步机构连锁的商户信息
    python manage.py update_2018_10_11_async_chain_hospital
    """

    def handle(self, *args, **options):
        merchantnonsyncs = MerchantNonsync.objects.all()
        for merchantnonsync in merchantnonsyncs:
            try:
                merchant = Merchant.objects.get(id=merchantnonsync.merchant_id)
                MerchantNonsync(merchant.doctor)
            except Exception as e:
                print e.message
                continue
        print ('Done')
