web 2 lat temu
commit
4eb8f3f64d
7 zmienionych plików z 150 dodań i 0 usunięć
  1. 8 0
      .gitignore
  2. 20 0
      .vscode/launch.json
  3. 38 0
      .vscode/settings.json
  4. BIN
      dist/msg
  5. 56 0
      msg.py
  6. 27 0
      package.sh
  7. 1 0
      requirements.txt

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+# ignore all except .gitignore file
+*.pyc
+*.spec
+output
+# dist
+log
+build
+# input

+ 20 - 0
.vscode/launch.json

@@ -0,0 +1,20 @@
+{
+    // 使用 IntelliSense 了解相关属性。 
+    // 悬停以查看现有属性的描述。
+    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Python: dingding-msg",
+            "type": "python",
+            "request": "launch",
+            "program": "${cwd}/msg.py",
+            "console": "integratedTerminal",
+            "args": [
+                "https://oapi.dingtalk.com/robot/send?access_token=1bda350b3a9c06",
+                "666",
+                "777"
+            ]
+        },
+    ]
+}

+ 38 - 0
.vscode/settings.json

@@ -0,0 +1,38 @@
+{
+  // "python.pythonPath": "/usr/bin/python3",
+  "python.defaultInterpreterPath": "/usr/local/python3.8/bin/python3",
+  "python.formatting.provider": "yapf",
+  "python.formatting.yapfArgs": [
+    "--style",
+    "{column_limit: 150}"
+  ],
+  "python.linting.pylintArgs": [
+    "--extension-pkg-allow-list=pydantic", // from pydantic import BaseModel 报缺失
+    "--function-naming-style=any", // 不限制函数名 命名规范
+    "--argument-naming-style=any", // 不限制参数名 命名规范
+    "--variable-naming-style=any", // 不限制变量名 命名规范
+    "--attr-naming-style=any", // 不限制属性名 命名规范
+    "--method-naming-style=any", // 不限制方法名 命名规范
+    "--const-naming-style=any", // 不限制常量名 命名规范
+    "--module-naming-style=any", // 不限制模块名 命名规范
+    "--max-line-length=500", // 单行最大长度
+    "--disable=C0116", // 忽略函数注释 missing-function-docstring
+    "--disable=C0115", // 忽略类注释 missing-class-docstring
+    "--disable=R0914", // 函数或方法有太多局部变量 too-many-locals
+    "--disable=R0913", // 函数或方法接受太多参数 too-many-arguments
+    "--disable=W0603", // 使用全局变量 global-statement
+    "--disable=R0912", // 函数或方法有太多分支 too-many-branches
+    "--disable=R0903", // 类的公共方法太少 too-few-public-methods
+    "--disable=R0902", // 当类有太多实例属性时使用,尝试减少该属性以获得更简单 too-many-instance-attributes
+    // "--disable=W1514", // 使用 open 而不明确指定编码 unspecified-encoding
+    "--disable=W0703" // 捕获过于笼统的异常 broad-except
+  ],
+  "python.testing.pytestArgs": [
+    ".",
+    "-s",
+    "-v"
+  ],
+  "python.testing.unittestEnabled": false,
+  "python.testing.pytestEnabled": true
+  //   "python.analysis.extraPaths": ["data-fastq", "data-fastq/utils"] // import 当前目录python文件 报错
+}

BIN
dist/msg


+ 56 - 0
msg.py

@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# coding=utf-8
+'''
+@Author: YTX (Tel:15610573978)
+@Date: 2022-11-15 16:30:46
+@LastEditors: YTX
+@LastEditTime: 2023-11-07 12:26:09
+'''
+
+import sys
+import time
+import json
+import requests
+from dingtalkchatbot.chatbot import DingtalkChatbot
+
+if len(sys.argv) < 2:
+    print("usage: python3 msg.py https://oapi.dingtalk.com/robo 通知1 通知2 ... ...")
+webhook = sys.argv[1]
+msg = ' '.join(i for i in sys.argv[2:])
+msg = msg + '\n' if msg == '' else '\n' + msg + '\n'
+
+postData = {
+    "object_kind": "push",
+    "ref": "refs/heads/master",
+    "user_name": "真正的内容",
+    "project": {},
+    "commits": [],
+    "repository": {
+        "name": "test",
+    }
+}
+
+
+class HeadersUtils():
+    headers = {"Content-Type": "application/json; charset=UTF-8"}
+
+
+def retrySendGitLabMsg(inputStr):
+    postData["user_name"] = inputStr + "\n"
+    try:
+        resRetry = requests.post(webhook, data=json.dumps(postData), timeout=(15, 15), headers=HeadersUtils.headers)
+        print(resRetry.text)
+    except Exception as error:
+        print("DingUtils.sendGitLabMsg失败:", error)
+
+
+xiaoding = DingtalkChatbot(webhook)
+
+try:
+    res = xiaoding.send_text(msg='# hello 信息通知: ' + msg + str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))))
+    if res['errcode'] != 0:
+        # LogUtils.error("钉钉通知失败:", res, self.json())
+        # 使用gitlab方式重试一次
+        retrySendGitLabMsg(msg)
+except Exception as e:
+    print("钉钉机器人发送失败:", e)

+ 27 - 0
package.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+path=$(cd $(dirname $0); pwd)
+#path=$(echo ~+)
+
+
+pynameList="
+msg
+"
+
+build(){
+    cd ${path} && mkdir -p ${path}/dist && rm -rf dist/*
+    for i in ${pynameList}; do
+        rm -rf ${i}.spec build __pycache__
+        pyinstaller -F ${i}.py
+        rm -rf ${i}.spec build __pycache__
+    done
+}
+
+
+echo ------------
+echo param: $1
+echo paramNum: $#
+echo ------------
+if [ -z "$1" ]; then build;
+else echo param must be "['']"
+fi
+echo ------------

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+DingtalkChatbot==1.5.3