interface.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:main.py
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. class Core(object):
  9. @staticmethod
  10. def check(self):
  11. pass
  12. # eros注册
  13. class init_path(Load):
  14. @Web.setting
  15. def post(self):
  16. Core.check(self)
  17. id = self.input('id')
  18. ip = self.input('ip')
  19. update = {}
  20. update['eros_status'] = 1
  21. update['eros_server'] = ip
  22. self.service('common').update('farm', id, update)
  23. self.out('ok')
  24. # 同步数据
  25. class sync_path(Load):
  26. @Web.setting
  27. def post(self):
  28. Core.check(self)
  29. data = self.input('data')
  30. table = self.input('table')
  31. if data:
  32. if '__' in data:
  33. param = data.split('__')
  34. data = {}
  35. data['type'] = param[3]
  36. data['gateway'] = param[4]
  37. data['device'] = param[1]
  38. data['hard'] = param[2]
  39. data['farm'] = param[0]
  40. data['source'] = param[5]
  41. data['value'] = param[6]
  42. data['time'] = Demeter.time()
  43. Demeter.model('data', 'tsdb').insert(data)
  44. else:
  45. data = json.loads(data)
  46. for v in data:
  47. update = {}
  48. if 'password' in v:
  49. Demeter.config['db_md5'] = 1
  50. info = self.service('common').one(table, id=v['id'])
  51. if info:
  52. id = v['id']
  53. del v['cdate']
  54. if 'udate' in v:
  55. del v['udate']
  56. del v['id']
  57. for i in v:
  58. if v[i]:
  59. update[i] = v[i]
  60. self.service('common').update(table, id, update, cdate=False)
  61. else:
  62. del v['cdate']
  63. if 'udate' in v:
  64. del v['udate']
  65. for i in v:
  66. if v[i]:
  67. update[i] = v[i]
  68. self.service('common').update(table, False, update)
  69. self.out('ok')