You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

notify.py 1.9 kB

3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. import sys
  4. import json
  5. class Sender(object):
  6. @classmethod
  7. def send_email(cls, payload):
  8. # already done in go code
  9. pass
  10. @classmethod
  11. def send_wecom(cls, payload):
  12. # already done in go code
  13. pass
  14. @classmethod
  15. def send_dingtalk(cls, payload):
  16. # already done in go code
  17. pass
  18. @classmethod
  19. def send_feishu(cls, payload):
  20. # already done in go code
  21. pass
  22. @classmethod
  23. def send_mm(cls, payload):
  24. # already done in go code
  25. pass
  26. @classmethod
  27. def send_sms(cls, payload):
  28. users = payload.get('event').get("notify_users_obj")
  29. phones = {}
  30. for u in users:
  31. if u.get("phone"):
  32. phones[u.get("phone")] = 1
  33. if phones:
  34. print("send_sms not implemented, phones: {}".format(phones.keys()))
  35. @classmethod
  36. def send_voice(cls, payload):
  37. users = payload.get('event').get("notify_users_obj")
  38. phones = {}
  39. for u in users:
  40. if u.get("phone"):
  41. phones[u.get("phone")] = 1
  42. if phones:
  43. print("send_voice not implemented, phones: {}".format(phones.keys()))
  44. def main():
  45. payload = json.load(sys.stdin)
  46. with open(".payload", 'w') as f:
  47. f.write(json.dumps(payload, indent=4))
  48. for ch in payload.get('event').get('notify_channels'):
  49. send_func_name = "send_{}".format(ch.strip())
  50. if not hasattr(Sender, send_func_name):
  51. print("function: {} not found", send_func_name)
  52. continue
  53. send_func = getattr(Sender, send_func_name)
  54. send_func(payload)
  55. def hello():
  56. print("hello nightingale")
  57. if __name__ == "__main__":
  58. if len(sys.argv) == 1:
  59. main()
  60. elif sys.argv[1] == "hello":
  61. hello()
  62. else:
  63. print("I am confused")