def test_send_action_card(self): dingding = DingDing(TOKEN) rep = dingding.send_action_card( "新用户注册", "![screenshot](@lADOpwk3K80C0M0FoA) \n## 请及时审核", [("通过", "http://www.baidu.com"), ("不通过", "http://www.qq.com")], ) self.assertEqual(rep["errmsg"], "ok")
def test_send_link(self): dingding = DingDing(TOKEN) rep = dingding.send_link( "天气提示", "天气不错", "http://www.weather.com.cn/", "https://cn.vuejs.org/images/logo.png", ) self.assertEqual(rep["errmsg"], "ok")
def test_send_single_action_card(self): dingding = DingDing(TOKEN) rep = dingding.send_single_action_card( "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", "![screenshot](@lADOpwk3K80C0M0FoA) \n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", "阅读全文", "https://www.dingtalk.com/", 0, 1, ) self.assertEqual(rep["errmsg"], "ok")
def act(self, subject, msg): messages = [msg] def write(msg): self.stderr.write('%s\n' % msg) self.stderr.flush() messages.append(msg) try: specs = self.rpc.supervisor.getAllProcessInfo() except Exception as e: write('Exception retrieving process info %s, not acting' % e) return waiting = list(self.programs) if self.any: write('Restarting all running processes') for spec in specs: name = spec['name'] group = spec['group'] self.restart(spec, write) namespec = make_namespec(group, name) if name in waiting: waiting.remove(name) if namespec in waiting: waiting.remove(namespec) else: write('Restarting selected processes %s' % self.programs) for spec in specs: name = spec['name'] group = spec['group'] namespec = make_namespec(group, name) if (name in self.programs) or (namespec in self.programs): self.restart(spec, write) if name in waiting: waiting.remove(name) if namespec in waiting: waiting.remove(namespec) if waiting: write( 'Programs not restarted because they did not exist: %s' % waiting) if self.email: message = '\n'.join(messages) self.mail(self.email, subject, message) if self.dingding: ding = DingDing(self.token) message = '\n'.join(messages) ding.send_text(message, at_all=True)
def test_send_feed_card(self): dingding = DingDing(TOKEN) rep = dingding.send_feed_card( [ ( "学vue", "https://cn.vuejs.org/", "https://cn.vuejs.org/images/logo.png", ), ( "哪家强", "https://cn.vuejs.org/", "https://cn.vuejs.org/images/logo.png", ), ] ) self.assertEqual(rep["errmsg"], "ok")
def real_time_data_acquisition(): # 获取单日股票情况 stock = Stock() gupiao_list = config.get("gupiao_list", "one") gupiao_list = json.loads(gupiao_list) res = stock.query_gupiao(gupiao_list) # 处理数据 deal = Deal() all_gupiao_data = deal.df_to_list(gupiao_list, res) dealed_data = Deal().to_text(data=all_gupiao_data) print(dealed_data) # 发送数据 dingding = DingDing() res = dingding.send_text(dealed_data) print(res) return res
def setup(): global ding if ding: return access_token = get_access_token() if len(access_token) <= 0: print "未设置钉钉群的access_token,无法启用钉钉功能" return ding = DingDing(access_token)
def test_parse_token(self): TestDing = namedtuple("TestDing", ["input", "want"]) tests = [ TestDing( "https://oapi.dingtalk.com/robot/send?access_token=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ", "https://oapi.dingtalk.com/robot/send?access_token=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ), TestDing( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ", "https://oapi.dingtalk.com/robot/send?access_token=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ), ] for test_ding in tests: d = DingDing(test_ding.input) self.assertEqual(d.url, test_ding.want)
from dingding import DingDing from stock import Stock from deal_data import Deal from utils import str_to_num import configparser config = configparser.ConfigParser() config.read_file(open('config.ini')) app = Celery("tasks") app.config_from_object("setting") deal = Deal() stock = Stock() dingding = DingDing() # 定时任务 app.conf.update( # CELERY_DEFAULT_EXCHANGE = 'tasks', CELERY_DEFAULT_EXCHANGE_TYPE='topic', CELERY_DEFAULT_ROUTING_KEY='default', CELERY_DEFAULT_EXCHANGE='default', CELERY_DEFAULT_QUEUE='default', CELERY_QUEUES=( Queue('default', Exchange='default', routing_key='default'), Queue('normal', Exchange='normal', routing_key='normal.#'), ), CELERY_ROUTES={ "tasks.warning_gupiao": { "queue": "normal",
def test_send_markdown(self): dingding = DingDing(TOKEN) rep = dingding.send_markdown("天气提示", "# 天气不错\n> 雨一直下") self.assertEqual(rep["errmsg"], "ok")
def test_send_text2(self): dingding = DingDing(TOKEN) rep = dingding.send_text("天气不错", [PHONE]) self.assertEqual(rep["errmsg"], "ok")
def test_send_markdown(self): time.sleep(1) dingding = DingDing(TOKEN) dingding.set_secret(SECRET) rep = dingding.send_markdown("天气提示", "# 天气不错\n> 雨一直下") self.assertEqual(rep["errmsg"], "ok")
def test_send_text2(self): time.sleep(1) dingding = DingDing(TOKEN) dingding.set_secret(SECRET) rep = dingding.send_text("天气不错", [PHONE]) self.assertEqual(rep["errmsg"], "ok")
#!/Users/lamber/python/longfor/bin/python import sh import json from dingding import DingDing access_token = 'b0d981254af985b4420065e72837242b92c2831cefcd51904e9acea96dcff766' ding = DingDing(access_token) """ 钉钉模块的使用方法 # @所有人 ding.send_text('hello', at_all=True) # @手机号为1333333333的人 ding.send_text('hello', ['13333333333']) ding.send_link('title', 'text', 'message_url') ding.send_markdown('title', 'text') ding.send_action_card('title', 'text', [('title1', 'url1'), ('title2', 'url2')]) ding.send_link( '时代的火车向前开', '这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。 而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?', 'https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI') """ headers1 = "Cookie: acw_tc=76b20f6315604061049676441e0da08812237984c33eb3fe31c8e3b020c40d; connect.sid=s%3Adu1IsBfjSSSoMXTj4341Y-Ev3nMhBuX-.FVAtmKDmftHevlQ3Niy2z5zZp214qsYYvB%2BAVQ8Y6AI; Hm_lvt_239619dd622d77b4aa84c2bc9c1d36f5=1560406106; Hm_lpvt_239619dd622d77b4aa84c2bc9c1d36f5=1560411466; u_asec=099%23KAFEtYEKEBSEhYTLEEEEEpEQz0yFD6ghDXiFS6gwDusYW6VFDu9FC6tFjYFET%2FdosyaStqMTEc35PE1laquYSpXfNVo63ya3OfYncYUquz8sDzXZ1d%2Fs4WxR6RXcaOnKPf8VNlWuV6yNSKoSLMss%2ByJkPRv3iOBT%2FfInNdbRzqk8SO2Ciou7t2wTPw2c9XyKVfp2NlVuVf3YSj%2BBaquYSpXfNVo63ya3OfYncYUquz8sDzXZ1d%2Fs4WxR6RXcaOnKPf8VNlWuV6yNSKoSLMss%2ByJkPRv3iOBT%2FfInNQOqrtxvG%2BpCaYe8SOvo6azt3%2F%2FpQt2Bvdbqztc2us2CE9%2F8SVhv4gvlEKXCVPcYU9buQ2iPCT82GJsAGuhYJcGTE1LlluZOt377llllWLaStETNllle33iSw6alluUdt37qY3llWLaStECEBEFE13lls6Xs9z8isYFETYilsslwtuYTEHIE%2BDSEjrN4kLISmQPvbht8fkv3iwl8qiUCqoCqKW6r2h5YwqVUPJK4IwkcvhWgfJ6%2FIHvkcrmo3kj2iEAkl%2BKDkxIRvwygciYZRKnyMOFYqwP%2BlYFETJDovlNXE7EFD67EE67TEEilluCV" hospital_url = """ curl '{"mode":"2","distId":"175","outpatientId":"1316410","departmentId":"","date":"","title":"","pageNum":1,"pageSize":10,"timeout":30000,"isLoading":true}' """ ret = sh.curl( "https://m.hsyuntai.com/med/hp/hospitals/100215/registration/regList", "-H", headers1, "-H",