loop.py 887 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 = 1000
  10. class Loop(object):
  11. def run(self):
  12. self.handle()
  13. time.sleep(timeSleep)
  14. # 开关设备
  15. def switch(self, value):
  16. Demeter.service('device').switchMul(value)
  17. def handle(self):
  18. model = Demeter.model('device_set_loop')
  19. cur = Demeter.time()
  20. date = Demeter.date(cur, '%Y-%m-%d-%w-%H-%M')
  21. date = date.split('-')
  22. week = date[3]
  23. day = date[2]
  24. model.status = True
  25. model.hour = date[4]
  26. model.minute = date[5]
  27. data = model.select()
  28. if data:
  29. for value in data:
  30. state = False
  31. value['loop'] = value['loop'].split(',')
  32. if value['looptype'] == 2:
  33. if week in value['loop']:
  34. state = True
  35. elif value['looptype'] == 3:
  36. if day in value['loop']:
  37. state = True
  38. if state:
  39. self.switch(value)