Skip to content

Latest commit

 

History

History
82 lines (69 loc) · 2.35 KB

README.md

File metadata and controls

82 lines (69 loc) · 2.35 KB

Knotify

Knotify is a simple tool that helps you to push notifications and other messages to the dedicated clients Include Telegram Bot, Webhook, WirePusher, Wechat Bot (Server Chan)

Quick Start

Use pip to install Knotify first:

pip install knotify

Then get the "key" from the client you want to use:

Use context manager for a quick and easy notification:

from knotify import WirePusher
async def main():
    async with WirePusher("Your_Token_From_WirePusher") as w:
        w.emit("FooBar")

If you want to keep the instance for a longer lifespan, remember to use await PusherInstance.close() afterwards:

from knotify import WirePusher
async def main():
    w = WirePusher("Your_Token_From_WirePusher")            
    await w.emit("Foo")
    await w.emit("Bar")
    await w.close()

Pre-defined Pushers

Webhook

The "key" will be the url you want to post to itself

e.g. Discord Server Webhook

Wechat

The wechat client is Server Chan(Server酱) and the key will be sckey

Telegram

The telegram client is tg_push_bot from Fndroid. Use Manual

WirePusher

WirePusher is an Android app that allows you to send push notifications right to your device.

Custom Pusher

Create a custom pusher by inheriting from BasePusher:

class CustomPusher(BasePusher):
    pass

And all you need to do is to overload the _push function which will be invoked by emit function:

async def _push(self, message, **kwargs) -> bool:
    """
    Overload this function to create custom pusher
    :param message: message to be sent
    :param kwargs: all params to be sent
        use function `_build_body` to build a dict for params
    :return: Returns True if pushing is succeeded, Otherwise False
    """
    pass

Use the built-in aiohttp.ClientSession to invoke http api and self._check_result to check result:

async def _push(self, message, **kwargs) -> bool:
    with self.s.get("api", data=kwargs) as result:
        return self._check_result(result)

Requirement

  • Python 3.6+
  • aiohttp

License

MIT License