V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
7ommy
V2EX  ›  分享创造

自己写的消息推送的 Python 库

  •  
  •   7ommy ·
    TommyMerlin · 85 天前 · 2169 次点击
    这是一个创建于 85 天前的主题,其中的信息可能已经有所发展或是发生改变。

    之前用过很多种消息推送的工具,比如企业微信、IYUU 、钉钉、Server 酱、GNotify 、Ntfy 等,所以就用 Python 写了个消息推送的小工具在项目的其他地方能快速调用发送消息,其实就是网络请求调用了一下官方提供的 API 。

    目前简单支持了企业微信、飞书、钉钉、Gotify 、Ntfy 、Server 酱、IYUU 、AnPush 、息知、传息、WPush 、PushPlus 、TG Bot 、Email ,还挺不完善的。

    项目地址: https://github.com/TommyMerlin/ANotify

    还是纯新手😶

    • 安装
    pip install anotify
    

    统一的调用格式:

    • 企业微信
    from ANotify import Nwecom
    # 企业 ID
    CORPID = ''
    # 应用 Secret
    CORPSECRET = ''
    # 应用 ID
    AgentId = ''
    
    wn = Nwecom.WxNotify(corpid=CORPID, corpsecret=CORPSECRET, agentid=AgentId)
    wn.send_msg("test message")
    wn.send_msg_markdown("**Hello**\n- test1\n- [ANotify]( https://github.com/TommyMerlin/ANotify)")
    wn.send_text_card("test title", "test content", "https://www.example.com")
    wn.send_file("./test.txt")
    wn.send_img("./test.png")
    
    • Gotify
    from ANotify import Ngotify
    TOKEN = ""
    SERVER_URL = ""
    gotify = Ngotify.GotifyNotify(SERVER_URL, TOKEN)
    gotify.send_msg("title", "content")
    gotify.send_msg("title", "**content**\n- No.1\n- No.2", Ngotify.MessageType.markdown)
    
    • Ntfy
    from ANotify import Nntfy
    TOPIC = ""
    URL = ""
    ntfy = Nntfy.NtfyNotify(TOPIC, URL)
    ntfy.send_msg("title", "content")
    
    • AnPush
    from ANotify import Nanpush
    TOKEN = ""
    anpush = Nanpush.AnpushNotify(TOKEN)
    anpush.send_msg("title", "content", "channel_id")
    

    其余的就不一一写了

    12 条回复    2024-07-08 23:30:53 +08:00
    jukanntenn
        1
    jukanntenn  
       85 天前
    apprise 看看呢?
    molika
        2
    molika  
       85 天前
    点赞!
    PS:async 可以支持下
    7ommy
        3
    7ommy  
    OP
       85 天前
    @jukanntenn 感谢大佬推荐
    Marcus233
        4
    Marcus233  
       85 天前
    能否支持读取用户目录的配置文件,就不用每次都填 secret 了
    7ommy
        5
    7ommy  
    OP
       85 天前
    @molika 感谢建议,TODO 列起来😊
    kile
        6
    kile  
       85 天前
    提个意见,三方库最好把入口收到一起,统一用一个类来管理

    不然用起来时候属实记不住你起得类名,就必须去查文档了
    改成这样不很舒服么


    ANototify.WXNotify()
    ANotify.DingDingNotify()
    ANotofy.GotifyNotify()
    7ommy
        7
    7ommy  
    OP
       85 天前
    @kile 感谢建议
    7ommy
        8
    7ommy  
    OP
       85 天前
    @kile 之前测试的时候都是 IDE 提示的类名,所以没做统一的处理
    AIGC2D
        9
    AIGC2D  
       85 天前
    Python 版,支持
    julyclyde
        10
    julyclyde  
       85 天前
    @Marcus233 一般后台服务都不会去支持“用户目录”下面的东西吧?
    后台服务一般都是 daemon 用户或者 nobody 之类的用户身份运行的
    SenLief
        11
    SenLief  
       85 天前
    这个是不是要统一推送接口才好。
    7ommy
        12
    7ommy  
    OP
       85 天前
    @SenLief 是的大佬,又在考虑进行重构,之前推送的渠道就几个,现在越来越多了调用起来就有点不太方便了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   990 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:31 · PVG 07:31 · LAX 16:31 · JFK 19:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.