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.8 kB

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
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  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_sms(cls, payload):
  24. users = payload.get('event').get("notify_users_obj")
  25. phones = {}
  26. for u in users:
  27. if u.get("phone"):
  28. phones[u.get("phone")] = 1
  29. if phones:
  30. print("send_sms not implemented, phones: {}".format(phones.keys()))
  31. @classmethod
  32. def send_voice(cls, payload):
  33. users = payload.get('event').get("notify_users_obj")
  34. phones = {}
  35. for u in users:
  36. if u.get("phone"):
  37. phones[u.get("phone")] = 1
  38. if phones:
  39. print("send_voice not implemented, phones: {}".format(phones.keys()))
  40. def main():
  41. payload = json.load(sys.stdin)
  42. with open(".payload", 'w') as f:
  43. f.write(json.dumps(payload, indent=4))
  44. for ch in payload.get('event').get('notify_channels'):
  45. send_func_name = "send_{}".format(ch.strip())
  46. if not hasattr(Sender, send_func_name):
  47. print("function: {} not found", send_func_name)
  48. continue
  49. send_func = getattr(Sender, send_func_name)
  50. send_func(payload)
  51. def hello():
  52. print("hello nightingale")
  53. if __name__ == "__main__":
  54. if len(sys.argv) == 1:
  55. main()
  56. elif sys.argv[1] == "hello":
  57. hello()
  58. else:
  59. print("I am confused")