123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- """
- feishu python方法
- """
- import json
- import requests
- import datetime
- class Feishu(object):
- """
- feishu Python Object
- """
- def __init__(self):
- self.document_url = (
- "https://w42nne6hzg.feishu.cn/sheets/C1Qrsa4HWh6bzEtv7aocrFlAnad"
- )
- self.robot_url = "https://open.feishu.cn/open-apis/bot/v2/hook/34e2fdbc-0649-44d3-b5ce-b28b38cca1db"
- self.headers = {"Content-Type": "application/json"}
- def insert(self):
- """
- 写入飞书表格
- :return:
- """
- return self.document_url
- def bot(self, platform_name, flag=1):
- """
- 飞书机器人,在群里报警用
- :param platform_name: 小程序的名称
- :param flag: 通知 or 报警, 默认为1, 通知
- :return:
- """
- if flag == 1:
- payload = {
- "msg_type": "interactive",
- "card": {
- "elements": [
- {
- "tag": "div",
- "text": {
- "content": "**{}**\n数据自动导出完成;\n完成时间是:{}。".format(
- platform_name, datetime.datetime.now().__str__()
- ),
- "tag": "lark_md",
- },
- },
- ],
- "header": {"title": {"content": "We分析: 通知 ✅", "tag": "plain_text"}},
- },
- }
- else:
- payload = {
- "msg_type": "interactive",
- "card": {
- "elements": [
- {
- "tag": "div",
- "text": {
- "content": "**{}**\n自动导出失败 !!!".format(
- platform_name
- ),
- "tag": "lark_md",
- },
- },
- ],
- "header": {"title": {"content": "We分析: 报警 ❌", "tag": "plain_text"}},
- },
- }
- w = requests.request(
- "POST", url=self.robot_url, headers=self.headers, data=json.dumps(payload)
- )
- print(w.json())
- # if response.status_code == 200:
- # return True
- # else:
- # print("飞书通知失败")
- # return
- # if __name__ == "__main__":
- # F = Feishu()
- # F.bot("票圈视频", 2)
|