timing.py 598 B

1234567891011121314151617181920212223242526272829303132
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web
  4. name:admin.py
  5. author:rabin
  6. """
  7. import time
  8. from demeter.core import *
  9. timeSleep = 60
  10. # 设置过期时间
  11. class Timing(object):
  12. def run(self):
  13. self.handle()
  14. time.sleep(timeSleep)
  15. # 开关设备
  16. def switch(self, value):
  17. Demeter.service('device').switchMul(value)
  18. def handle(self):
  19. model = Demeter.model('device_set_timing')
  20. model.status = 0
  21. cur = Demeter.time()
  22. model.zdate.assign(cur, '<=')
  23. data = model.select()
  24. if data:
  25. for value in data:
  26. self.switch(value)
  27. model.id = value['id']
  28. model.update(status=1)