def foo2(): wBot(url)\ .set_text("every 30 seconds")\ .set_mentioned_list(["wangqing", "@all"])\ .set_mentioned_mobile_list(["13800001111", "@all"])\ .every(30)\ .run()
def foo4(): # 当同时调用了 render_text 与 set_text 时,优先调用 render_text # type 选项: 'text', 'markdown', 默认为 text wBot(url)\ .render_text(render_text, args=['render ', 'with '], kwargs={'arg3': 'function'}, type='text')\ .check(check_something, args=['arg1', 'arg2'], kwargs={'arg3': 'arg3'})\ .every(30)\ .run()
def main(): url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2a599e1c-9ec7-4f64-ad18-cf7cdfdca8249' rs = wBot(url).set_text("hello from Python3,使用vscode编辑").send() wBot(url).set_text('<font color="info">markdown HTML文本,测试</font>', type='markdown').send() print('发送成功?') pass
def foo5(): # 在调用 check 5 次,或发送 3 次后停止运行 wBot(url)\ .set_check_counter(5)\ .set_send_counter(3) \ .check(check_something, args=['arg1', 'arg2'], kwargs={'arg3': 'arg3'})\ .set_text("every 30 seconds")\ .every(30)\ .run()
def test_check_false(): msgs = wBot(url) \ .set_check_counter(5)\ .set_text("every 2 seconds with condition") \ .check(is_false, args=[True, True], kwargs={'arg3': False}) \ .every(2) \ .run() assert msgs == []
def foo7(): bots1 = BotMgr() bots2 = BotMgr() bots3 = BotMgr() bot1 = wBot(url)\ .set_check_counter(5)\ .set_send_counter(3) \ .check(check_something, ['arg1', 'arg2'], {'arg3': 'arg3'})\ .set_text("every 30 seconds")\ .every(30) bot2 = wBot(url) \ .set_check_counter(6) \ .set_send_counter(5) \ .check(check_something, ['arg1', 'arg2'], {'arg3': 'arg3'}) \ .set_text("every 10 minutes") \ .every(minute=10) bot3 = wBot(url) \ .set_check_counter(6) \ .set_send_counter(5) \ .check(check_something, ['arg1', 'arg2'], {'arg3': 'arg3'}) \ .set_text("every 10 minutes") \ .every(hour=1) bots1.append(bot1) bots1.append(bot2) bots2.append(bot2) bots2.append(bot3) bots3.append(bot1) bots3.append(bot3) bots1.start() bots2.start() bots3.start() bots1.join() bots2.join() bots3.join()
def test_hello_world(): msg = wBot(url).set_text("hello world").send() assert msg == ( "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=fakekey", { "msgtype": "text", "text": { "content": "hello world", "mentioned_list": [], "mentioned_mobile_list": [] } })
def test_check_true(): msgs = wBot(url)\ .set_send_counter(3)\ .set_text("every 2 seconds with condition")\ .check(is_true, args=[True, True], kwargs={'arg3': True})\ .every(2)\ .run() assert len(msgs) == 3 assert msgs[0] == ( "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=fakekey", { "msgtype": "text", "text": { "content": "every 2 seconds with condition", "mentioned_list": [], "mentioned_mobile_list": [] } })
def test_hello_world_twice(): bot = wBot(url) msg1 = bot.set_text('hello world').send() msg2 = bot.set_text('hello world again', type='markdown').send() assert msg1 == ( "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=fakekey", { "msgtype": "text", "text": { "content": "hello world", "mentioned_list": [], "mentioned_mobile_list": [] } }) assert msg2 == ( "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=fakekey", { "msgtype": "markdown", "markdown": { "content": "hello world again", } })
def hello_world(): wBot(url).set_text("hello world").send()
def foo3(): wBot(url)\ .set_text("every 30 seconds with condition")\ .check(check_something, args=['arg1', 'arg2'], kwargs={'arg3': 'arg3'})\ .every(30)\ .run()
def foo1(): wBot(url).set_text("every 30 seconds").every(30).run()
def run_forever(): # 每隔 60 秒发送一次 hello world # 使用Bot.every() 设置间隔 wBot(url).set_text("hello world").run()
def hello_world_twice(): bot = wBot(url) bot.set_text('hello world').send() bot.set_text('<font color="info">Hello world</font>', type='markdown').send()