• 消息定时通知=维格表+python/维格表+影刀


    维格表 API:https://vika.cn/developers/api/introduction

    前言
    在这里插入图片描述
    不搭后语
    在这里插入图片描述

    维格表+影刀

    读取信息

    在这里插入图片描述
    影刀配置:
    第一步:安装维格表指令
    在这里插入图片描述
    第二步:从维格表中获取token和表ID,不懂请看下这个https://vika.cn/developers/api/introduction
    在这里插入图片描述
    第三步:由于josn数据无法通过企业微信推送出去,就这里添加了一个转换
    在这里插入图片描述
    第四步:按照需求,添加一个IF,意思是如果变量text_instance中包含未完成,则执行下一步
    在这里插入图片描述
    IF的下一步就是,通过企业微信将数据推送出去
    在这里插入图片描述
    这里可以自己加描述,比如“XX未完成”
    在这里插入图片描述
    执行结果:
    在这里插入图片描述
    这样就完成了,这样有了思路之后,因为影刀的底层也是python,可以帮忙我们通过python去实现这个工作流程,因为python运行会比影刀稳定(毕竟影刀是软件,需要运行环境稳定)

    维格表+python

    读取信息

    在这里插入图片描述

    # -*- coding:utf-8 -*-
    import requests
    
    request_url = 'https://api.vika.cn/fusion/v1/datasheets/{dst6acwpZmEi9Qw9Ka}/records'
    headers = {"Authorization": "Bearer {uskgx99Og4NEJoDRyi4elxx你自己的token}","Content-Type":"application/json"}
    response = requests.get(request_url, headers=headers)
    result = response.json()
    from vika import Vika
    vika = Vika("uskgx99Og4NEJoDRyi4elXX你自己的token")
    
    
    dst = vika.datasheet("dst6acwpZmEi9Qw9Ka")
    records = dst.records.all(viewId="viw5x0DKGgmPy")
    records = dst.records.all(fields=["姓名","核酸"])
    for record in records:
      print(record.json())
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    在这里插入图片描述

    信息更新

    # -*- coding:utf-8 -*-
    # 1、发送 HTTPS 请求
    import requests
    request_url = 'https://api.vika.cn/fusion/v1/datasheets/{dst6acwpZmEi9Qw9XX}/records'
    headers = {"Authorization": "Bearer {uskgx99Og4NEJoDRyi4elXX}","Content-Type":"application/json"}
    response = requests.get(request_url, headers=headers)
    result = response.json()
    # 2、初始化 Python SDK
    from vika import Vika
    vika = Vika("uskgx99Og4NEJoDRyi4elXX")
    
    # 3、创建记录
    dst = vika.datasheet("dst6acwpZmEi9Qw9Ka")
    records = dst.records.create([
    {
        "姓名": "李"
    }
    ])
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    在这里插入图片描述

    信息转换

    由于企业微信无法发送json格式,需要将json转换为文本
    json.loads:将已编码的 JSON 字符串解码为 Python 对象

    import json
     
    data={"name":"sunxiaomin","sex":"男","年龄":"26"}
    #将python字典类型变成json数据格式
    json_str=json.dumps(data)
    print(json_str)
    print(type(json_str))
    #将JSON数据解码为dict(字典)
    data1=json.loads(json_str)
    print(data1)
    print(type(data1))
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    result = open("keyword.json","r",encoding="utf-8")
    print(type(result))   # 
    data = json.load(result)
    print(type(data))   #  
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    # 1.打开一个本地json文件
    data = open("./a.json", encoding='utf-8')
    # 反序列化,转换为python对象
    result = json.load(data)
    print(result)
    
    # 2.获取在线的json数据(王者荣耀英雄列表的json数据)
    json_url = 'https://pvp.qq.com/web201605/js/herolist.json'
    # 获取该json数据的文本(字符串)
    text = requests.get(json_url).text
    print(text)
    # 反序列化,转换为python对象
    result = json.loads(text)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    import json
    import csv
    
    """
    需求:将json中的数据转换成csv文件
    """
    def csv_json():
        # 1.分别 读,创建文件
        json_fp = open("word.json", "r",encoding='utf-8')
        csv_fp = open("word.csv", "w",encoding='utf-8',newline='')
    
        # 2.提出表头和表的内容
        data_list = json.load(json_fp)
        sheet_title = data_list[0].keys()
        # sheet_title = {"姓名","年龄"}  # 将表头改为中文
        sheet_data = []
        for data in data_list:
            sheet_data.append(data.values())
    
        # 3.csv 写入器
        writer = csv.writer(csv_fp)
    
        # 4.写入表头
        writer.writerow(sheet_title)
    
        # 5.写入内容
        writer.writerows(sheet_data)
    
        # 6.关闭两个文件
        json_fp.close()
        csv_fp.close()
    
    
    if __name__ == "__main__":
        csv_json()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    import json
    data = {
        'number' : 1307230000,
        'name' : 'christy',
        'buer' : False,
        "nul" : None
    }
    print("原始数据:",data)
    j_str = json.dumps(data)
    print("转换成json后的数据:",j_str)
    l_str = json.loads(j_str)
    print("转换成字典类型后的数据:",l_str)
    
    输出结果:
    原始数据: {'number': 1307230000, 'name': 'christy', 'buer': False, 'nul': None}
    转换成json后的数据: {"number": 1307230000, "name": "christy", "buer": false, "nul": null}
    转换成字典类型后的数据: {'number': 1307230000, 'name': 'christy', 'buer': False, 'nul': None}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    信息写入

    信息推送

    企业微信接口文档

    import requests
    # 10、企业微信机器人发送消息:文本消息
    url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1bd9d632-1f3b-445d-98e8-429a1d7415xx"
    headers = {"Content-Type": "text/plain"}   
    data = {
        "msgtype": "text",
        "text": {
            "content" : "data"
        }
    }
    r = requests.post(url,headers=headers,json=data,verify=False)#企业微信群机器人的消息虽然是“text”类型的,但是post发送过去的头部是“application/json”,是json格式的
    print(r.text)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    钉钉接口文档https://open.dingtalk.com/document/org/application-types
    钉钉改写接口文档:https://blog.csdn.net/Easzz/article/details/77140685

    json数据推送到开放接口软件,如企业微信

    通过企业微信自建应用向微信推送信息https://blog.csdn.net/as604049322/article/details/125898066

    import requests
    
    
    def send_message(message):
        userid = 'FangDuiQin'  # userid
        agentid = '1000002' # 应用ID
        corpsecret = 'zsfD4HMY95fCwOMO3mEe8qNaeVMJJOAbjSsyBO86wVc'  # Secret
        corpid = 'wwb559f1182c7a9cc0' # 企业ID
        
        res = requests.get(f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={corpsecret}")
        access_token = res.json()['access_token']
        
        json_dict = {
           "touser" : userid,
           "msgtype" : "text",
           "agentid" : agentid,
           "text" : {
               "content" : message
           },
           "safe": 0,
           "enable_id_trans": 0,
           "enable_duplicate_check": 0,
           "duplicate_check_interval": 1800
        }
        json_str = json.dumps(json_dict, separators=(',', ':'))
        res = requests.post(f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}", data=json_str)
        return res.json()['errmsg'] == 'ok'
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    实现企业微信机器人自动发消息:https://blog.csdn.net/yhhwatl/article/details/113484521

    
    '''
    Date: 2021-01-31 18:57:35
    LastEditors: yanghh
    LastEditTime: 2021-01-31 18:57:59
    FilePath: /roh5/Users/yanghh/Desktop/notify.py
    '''
    from urllib import request
    import os
    import json
    import sys
    
    Version = sys.argv[1]
    
    
    def http_post(url, data_json):
        jdata = json.dumps(data_json).encode()
        # print('jdata ',jdata)
        req = request.Request(url, jdata)
        response = request.urlopen(req)
        return response.read()
    
    
    url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=zsfD4HMY95fCwOMO3mEe8qNaeVMJJOAbjSsyBO86wVc'
    data_json = {'msgtype': 'text', 'text': {
        "content": "BiliBili传包完成,请通知KK设置审核服版本号{0},二维码地址:https://miniapp.bilibili.com/smallapp/#/app/devmng/biligamexxxxxxx".format(
            Version),
        "mentioned_mobile_list": ["12345657", "424575658"]
    }}
    resp = http_post(url, data_json)
    print("resp ", resp)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    用 Python 发送通知到企业微信https://blog.csdn.net/shammy_feng/article/details/123711347

    import json
    import time
    import requests
    '''
    本文件主要实现通过企业微信应用给企业成员发消息
    '''
    
    CORP_ID = "wwb559f1182c7a9cc0"
    SECRET = "zsfD4HMY95fCwOMO3mEe8qNaeVMJJOAbjSsyBO86wVc"
    
    class WeChatPub:
        s = requests.session()
    
        def __init__(self):
            self.token = self.get_token()
    
        def get_token(self):
            url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={SECRET}"
            rep = self.s.get(url)
            if rep.status_code != 200:
                print("request failed.")
                return
            return json.loads(rep.content)['access_token']
    
        def send_msg(self, content):
            url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + self.token
            header = {
                "Content-Type": "application/json"
            }
            form_data = {
                "touser": "FangDuiQin",#接收人
                "toparty": "1",#接收部门
                "totag": " TagID1 | TagID2 ",#通讯录标签id
                "msgtype": "textcard",
                "agentid": 1000002,#应用ID
                "textcard": {
                    "title": "债券打新提醒",
                    "description": content,
                    "url": "URL",
                    "btntxt": "更多"
                },
                "safe": 0
            }
            rep = self.s.post(url, data=json.dumps(form_data).encode('utf-8'), headers=header)
            if rep.status_code != 200:
                print("request failed.")
                return
            return json.loads(rep.content)
    
    if __name__ == "__main__":
        wechat = WeChatPub()
        timenow = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
        wechat.send_msg(f"
    {timenow}
    注意!
    今日有新债,坚持打新!
    "
    ) print('消息已发送!')
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
  • 相关阅读:
    【C语言小例程26/100】
    halcon 区域Region(HObject)的传输
    【C++】vector的认识+模拟实现
    Python_15 ddt驱动与日志
    自绘 控件
    【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
    记一次oracle存储过程转mysql百万级数据量 java代码查询 插入修改过程
    Java多线程/总述
    [MTK6771] android13系统启用OMAPI 支持esim.me
    pipeline agent分布式构建
  • 原文地址:https://blog.csdn.net/stqer/article/details/126493757