2019-03-14 14:06:31 3459浏览
今天扣丁学堂Python培训老师给大家分享一篇关于python3实现钉钉消息推送的方法示例详解,首先偶然发现一个python实现的按照农历/阴历推送消息提醒的程序,钉钉群消息推送。此处总结并对其可推送的消息做。
pip install schedule #实现定时任务的模块 pip install DingtalkChatbot #python封装的各种消息的调用 pip install sxtwl #日历库
import time
def One2TwoDigit(a):
a= int(a)
if a<10:
a = '0'+str(a)
else:
a=a
return str(a)
def addYear(monthDay):
monthDay = (time.strftime("%Y")) + str(monthDay)
return monthDay
#coding:utf8
import datetime
def date_part(date='20170301'):
global year,month,day
year=date[0:4]
month_first=int(date[4:5])
month = date[5:6]
if month_first ==0:
month = date[5:6]
else :
month = date[4:6]
day=date[6:8]
year = int(year)
month = int(month)
day = int(day)
d = datetime.date(year,month,day)
return d
# -*- coding: UTF-8 -*-
'''
pip install DingtalkChatbot
pip install sxtwl
'''
from dingtalkchatbot.chatbot import DingtalkChatbot
import time
import sxtwl
lunar = sxtwl.Lunar()
from One2TwoDigit import One2TwoDigit,addYear
from differ_days import date_part
import datetime
# 初始化机器人小丁
webhook = 'https://oapi.dingtalk.com/robot/send?access_token=' #填写你自己创建的机器人
xiaoding = DingtalkChatbot(webhook)
ymc = ["11", "12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10" ]
rmc = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]
def birthdayNotice_job(bri_name,bri_mon,bri_day,futureDays=3):
print("birthdayNotice_job is working...")
dayYinli2Yangli = lunar.getDayByLunar(int(time.strftime("%Y")), bri_mon, bri_day , False) #查询阴历2018年10月20日的信息,最后一个False表示是否是润月,填True的时候只有当年有润月的时候才生效
yangliDay = (str(dayYinli2Yangli.y) + One2TwoDigit(str(dayYinli2Yangli.m)) + One2TwoDigit(str(dayYinli2Yangli.d)))
yangliDayMsg ='农历:' + (str(bri_mon) + '月' + (str(bri_day)) + '日' )
print(bri_name+'阳历生日是:'+yangliDay)
d2 = date_part(yangliDay)
d1 = date_part(date=datetime.datetime.now().strftime('%Y%m%d'))
differ_day = (d2 - d1).days
if 0<differ_day<=futureDays:
name = bri_name
xiaoding.send_text(msg= yangliDayMsg + '是【' + name + '】的生日
标签:
Python培训
Python视频教程
Python在线视频
Python学习视频
Python培训班