# -*- coding: utf-8 -*- # !/usr/bin/env python import datetime import logging from typing import TYPE_CHECKING from apps.web.core.accounting import Accounting from apps.web.device.models import Device if TYPE_CHECKING: from apps.web.device.models import DeviceDict logger = logging.getLogger(__name__) def pollDeviceInfo(device, major, minor, year, month, day, coins): # type: (DeviceDict, str, str, int, int, int, int)->None def recordReport(device, year, month, day, putCoins): report_date = '%04d-%02d-%02d' % (year, month, day) Accounting.syncOfflineCoin(device, report_date, int(coins)) hwVer = 'v%s.%s' % (major, minor) if hwVer != device.hwVer: Device.update_field(dev_no = device['devNo'], hwVer = hwVer) if year == 0 or month == 0 or day == 0: nowTime = datetime.datetime.now() year = nowTime.year month = nowTime.month day = nowTime.day logger.debug('devNo = %s; major = %s; minor = %s; time = %04d-%02d-%02d; coins = %d' % ( device['devNo'], major, minor, year, month, day, coins)) recordReport(device, year, month, day, coins)