You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from enum import Enum
import time
from dingtalkchatbot.chatbot import DingtalkChatbot
from contextlib import contextmanager
from contextlib import closing
class sendkind(Enum):
text = 't'
link = 'l'
image = 'i'
markdown = 'm'
action_card = 'a'
feed_card = 'f'
def pushMsg(self):
kindsendfunc = 'self.xiaoding.send_%s'%self.kind.name
yield eval('%s(**self.msgargs)'%kindsendfunc)
def demo(self):
for t in range(self.retry):
time.sleep(4**t)
with closing(self.pushMsg()) as push:
print(push)
for i in push:
print('in for',i)
print(i)
if i['errcode']==0 and i['errmsg']=='ok':
break
if name == 'main':
dingRobot().demo()
The text was updated successfully, but these errors were encountered:
这个模块相当好,但还需要再封装成一个通用的模块。代码dingRobotDev.py如下:直接运行此文件python3 dingRobotDev.py 即可运行demo的text模式,发送如果失败,有三次机会发送。不足之处请指正。
#!/usr/env/python3
#encoding=utf-8
from enum import Enum
import time
from dingtalkchatbot.chatbot import DingtalkChatbot
from contextlib import contextmanager
from contextlib import closing
class sendkind(Enum):
text = 't'
link = 'l'
image = 'i'
markdown = 'm'
action_card = 'a'
feed_card = 'f'
class dingRobot(object):
def init(self,webhook='YOURWEBHOOK',secret=None,pc_slide=None,kind=sendkind.text,
msgargs={'msg':'我就是小丁,小丁就是我!','is_at_all':True},retry=3,flag=True):
self.webhook=webhook
self.secret=secret
self.pc_slide=pc_slide
self.kind=kind
print(self.kind)
print(self.kind.value)
print(self.kind.name)
self.msgargs=msgargs
self.retry=retry
self.flag=flag
self.kw = {'secret':self.secret,'pc_slide':self.pc_slide}
#self.xiaoding = None
self.xiaoding = DingtalkChatbot(self.webhook,**self.kw)
if name == 'main':
dingRobot().demo()
The text was updated successfully, but these errors were encountered: