Browse Source

Initial commit

“蒋伟” 6 months ago
parent
commit
6fad31f5cf
1 changed files with 28 additions and 32 deletions
  1. 28 32
      DingDing.py

+ 28 - 32
DingDing.py

@@ -35,11 +35,20 @@ else:
 使用钉钉机器人的接口,拼接后推送text
 '''
 
-
 # url = 'https://oapi.dingtalk.com/robot/send?access_token=f8566d2ed0feb8dc3bf2856df161241a8cf5a4c76af3d903abcabfdebebdff0e'  # webhook
 
 
-def DingTalkSend(info):
+text1 = (
+        f"<font color=\'#FFA500\'>[通知] </font>星辰绘影-服务巡检"
+        "\n\n服务巡检情况: " + "正常" +
+        "\n\n播报时间: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
+text2 = (
+        f"<font color=\'#FFA500\'>[通知] </font>星辰绘影-服务巡检"
+        '''\n\n<font>服务巡检情况: </font><font color=\'#FF0000\' size=2>异常</font> \n\n''' +
+        "\n\n播报时间: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
+
+
+def DingTalkSend(text1, text2):
     d = {}
     # 获取项目绝对路径
     path = Path(__file__).parent
@@ -55,41 +64,28 @@ def DingTalkSend(info):
             d.update({launch_name: num})
     print(d)
     f.close()
-    # retries_run = d.get('launch_retries_run')  # 运行总数
-    # print('运行总数:{}'.format(retries_run))
-    # status_defects = d.get('launch_problems_test_defects')  # 未执行数
-    # if status_defects is None:
-    #     status_defects = "0"
-    # else:
-    #     status_defects = status_defects
-    # print(status_defects)
-    # status_passed = d.get('launch_status_passed')  # 通过数量
-    # print('通过数量:{}'.format(status_passed))
     status_failed = d.get('launch_status_broken')  # 不通过数量
     print('不通过数量:{}'.format(status_failed))
 
     # 钉钉推送
-    text1 = (
-            f"<font color=\'#FFA500\'>[通知] </font>星辰绘影-{info}"
-            "\n\n服务巡检情况: " + "正常" +
-            "\n\n播报时间: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
-    text2 = (
-            f"<font color=\'#FFA500\'>[通知] </font>星辰绘影-{info}"
-            '''\n\n<font>服务巡检情况: </font><font color=\'#FF0000\' size=2>异常</font> \n\n''' +
-            "\n\n播报时间: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
     print(type(status_failed))
-    try:
-        if status_failed == "0":
-            print("我要发text1")
-            dd_robot = DingtalkChatbot(read_config_yaml("dingding", "test_yunwin_webhook"))
-            ret = dd_robot.send_markdown(title='星辰绘影服务巡检', text=text1, is_at_all=False)
-        else:
-            print("我要发text2")
-            dd_robot = DingtalkChatbot(read_config_yaml("dingding", "test_yunwin_webhook"))
-            ret = dd_robot.send_markdown(title='星辰绘影服务巡检', text=text2, is_at_all=False)
-    except Exception as e:
-        pass
+    dd_robot = DingtalkChatbot(read_config_yaml("dingding", "test_yunwin_webhook"))
+    if status_failed == "0":
+        dd_robot.send_markdown(title='星辰绘影服务巡检', text=text1, is_at_all=False)
+    else:
+        dd_robot.send_markdown(title='星辰绘影服务巡检', text=text2, is_at_all=False)
+    # try:
+    #     if status_failed == "0":
+    #         print("我要发text1")
+    #         dd_robot = DingtalkChatbot(read_config_yaml("dingding", "test_yunwin_webhook"))
+    #         dd_robot.send_markdown(title='星辰绘影服务巡检', text=text1, is_at_all=False)
+    #     else:
+    #         print("我要发text2")
+    #         dd_robot = DingtalkChatbot(read_config_yaml("dingding", "test_yunwin_webhook"))
+    #         dd_robot.send_markdown(title='星辰绘影服务巡检', text=text2, is_at_all=False)
+    # except Exception as e:
+    #     pass
 
 
 if __name__ == '__main__':
-    DingTalkSend("服务巡检")
+    DingTalkSend( text1, text2)