12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- """
- @author: luojunhui
- """
- import json
- import requests
- from applications.decoratorApi import retryOnTimeout
- def create_feishu_table(title, columns, rows):
- """
- create feishu table
- :param title:
- :param columns:
- :param rows:
- """
- table_base = {
- "header": {
- "template": "blue",
- "title": {
- "content": title,
- "tag": "plain_text"
- }
- },
- "elements": [
- {
- "tag": "table",
- "page_size": len(rows) + 1,
- "row_height": "low",
- "header_style": {
- "text_align": "left",
- "text_size": "normal",
- "background_style": "none",
- "text_color": "grey",
- "bold": True,
- "lines": 1
- },
- "columns": columns,
- "rows": rows
- }
- ]
- }
- return table_base
- @retryOnTimeout()
- def bot(title, detail, mention=True):
- """
- 机器人
- """
- title_obj = {
- "content": "{}<at id=all></at>\n".format(title) if mention else "{}\n".format(title),
- "tag": "lark_md",
- }
- head_title = "【重点关注】" if mention else "【普通通知】"
- url = "https://open.feishu.cn/open-apis/bot/v2/hook/b44333f2-16c0-4cb1-af01-d135f8704410"
- headers = {"Content-Type": "application/json"}
- payload = {
- "msg_type": "interactive",
- "card": {
- "elements": [
- {
- "tag": "div",
- "text": title_obj,
- },
- {
- "tag": "div",
- "text": {
- "content": json.dumps(
- detail, ensure_ascii=False, indent=4
- ),
- "tag": "lark_md",
- },
- },
- ],
- "header": {"title": {"content": head_title, "tag": "plain_text"}},
- },
- }
- requests.request("POST", url=url, headers=headers, data=json.dumps(payload), timeout=10)
|