utils.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import datetime
  4. import logging
  5. from typing import TYPE_CHECKING
  6. from apps.web.core.accounting import Accounting
  7. from apps.web.device.models import Device
  8. if TYPE_CHECKING:
  9. from apps.web.device.models import DeviceDict
  10. logger = logging.getLogger(__name__)
  11. def pollDeviceInfo(device, major, minor, year, month, day, coins):
  12. # type: (DeviceDict, str, str, int, int, int, int)->None
  13. def recordReport(device, year, month, day, putCoins):
  14. report_date = '%04d-%02d-%02d' % (year, month, day)
  15. Accounting.syncOfflineCoin(device, report_date, int(coins))
  16. hwVer = 'v%s.%s' % (major, minor)
  17. if hwVer != device.hwVer:
  18. Device.update_field(dev_no = device['devNo'], hwVer = hwVer)
  19. if year == 0 or month == 0 or day == 0:
  20. nowTime = datetime.datetime.now()
  21. year = nowTime.year
  22. month = nowTime.month
  23. day = nowTime.day
  24. logger.debug('devNo = %s; major = %s; minor = %s; time = %04d-%02d-%02d; coins = %d' % (
  25. device['devNo'], major, minor, year, month, day, coins))
  26. recordReport(device, year, month, day, coins)