def handle(self, *args, **options): print "start core" to_refill = [] not_to_refill = [] today = datetime.now(timezone('US/Eastern')).date() start_date = datetime.combine(today - timedelta(days=7), time.min) for autorefill in AutoRefill.objects.filter(enabled=True, trigger=AutoRefill.TRIGGER_SC, renewal_date__range=(datetime.now().date() - timedelta(days=64), datetime.now().date()))\ .exclude(renewal_date=None).exclude(schedule='').exclude(schedule=None): if autorefill.renewal_date < datetime.now(timezone('US/Eastern')).date(): result = get_mdn_status(autorefill.phone_number, autorefill.company) if not result['login_exception'] and result['status_find'] and\ result['renewal_date'] and result['renewal_date'] > datetime.now(timezone('US/Eastern')).date(): to_refill.append(autorefill.get_full_url()) if Transaction.objects.filter(autorefill=autorefill, started__gt=start_date): transaction = Transaction.objects.filter(autorefill=autorefill, started__gt=start_date)[0] else: if not autorefill.check_renewal_end_date(today=today): continue transaction = Transaction.objects.create(user=autorefill.user, autorefill=autorefill, state="Q", company=autorefill.company, triggered_by='System') if transaction.completed: continue if autorefill.need_buy_pins and transaction.pin: transaction.state = Transaction.COMPLETED transaction.save() continue transaction.state = Transaction.PROCESS transaction.save() queue_refill.delay(transaction.id) autorefill.renewal_date = result['renewal_date'] autorefill.save() else: not_to_refill.append(autorefill.get_full_url()) print 'Was refiled: ', to_refill print 'Wasn\'t refiled: ', not_to_refill
def handle(self, *args, **options): print "start core" not_refilled = [] refilled = [] notified = [] for transaction in Transaction.objects.filter(started__range=(datetime.datetime.combine(datetime.date(2015, 11, 07), datetime.time.min), datetime.datetime.combine(datetime.date(2015, 11, 07), datetime.time.max)), state=Transaction.INTERMEDIATE): if transaction.autorefill: try: result = get_mdn_status(transaction.autorefill.phone_number, transaction.autorefill.company) except Exception as e: not_refilled.append('Not refilled: ' + transaction.get_full_url()) continue if not result['login_exception']: if 'renewal_date' in result and (not result['renewal_date'] or result['renewal_date'] == datetime.date(2015, 11, 8)): refilled.append('Refilled: ' + transaction.get_full_url()) autorefill = transaction.autorefill autorefill.renewal_date = datetime.date(2015, 11, 8) autorefill.save() autorefill.set_renewal_date_to_next(today=autorefill.renewal_date) queue_refill.delay(transaction.id) send_with = transaction.autorefill.customer.send_status if send_with == 'NO': send_with = 'EM'