1,使用微信,定時往指定的微信羣裏發送指定信息。微信
2,須要發送的內容使用excel進行維護,指定要發送的微信羣名、時間、內容。工具
1,itchat:這個是主要的工具,用於鏈接微信我的帳號接口。如下是一些相關的知識點網站。網站
2,xlrd:這個是用來讀Excel文件的工具。spa
3,apscheduler:這個是用來定時調度時間的工具。excel
# coding=utf-8 from datetime import datetime import itchat import xlrd from apscheduler.schedulers.background import BlockingScheduler import os def SentChatRoomsMsg(name, context): itchat.get_chatrooms(update=True) iRoom = itchat.search_chatrooms(name) for room in iRoom: if room['NickName'] == name: userName = room['UserName'] break itchat.send_msg(context, userName) print("發送時間:" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n" "發送到:" + name + "\n" "發送內容:" + context + "\n") print("*********************************************************************************") scheduler.print_jobs() def loginCallback(): print("***登陸成功***") def exitCallback(): print("***已退出***") itchat.auto_login(hotReload=True, enableCmdQR=True, loginCallback=loginCallback, exitCallback=exitCallback) workbook = xlrd.open_workbook( os.path.join(os.path.dirname(os.path.realpath(__file__)), "chatroomsfile\AutoSentChatroom.xlsx")) # workbook = xlrd.open_workbook("D:\PyCharmCode\AutoLiulishouWechat\chatroomsfile\AutoSentChatroom.xlsx") sheet = workbook.sheet_by_name('Chatrooms') iRows = sheet.nrows scheduler = BlockingScheduler() index = 1 for i in range(1, iRows): textList = sheet.row_values(i) name = textList[0] context = textList[2] float_dateTime = textList[1] date_value = xlrd.xldate_as_tuple(float_dateTime, workbook.datemode) date_value = datetime(*date_value[:5]) if datetime.now() > date_value: continue date_value = date_value.strftime('%Y-%m-%d %H:%M:%S') textList[1] = date_value scheduler.add_job(SentChatRoomsMsg, 'date', run_date=date_value, kwargs={"name": name, "context": context}) print("任務" + str(index) + ":\n" "待發送時間:" + date_value + "\n" "待發送到:" + name + "\n" "待發送內容:" + context + "\n" "******************************************************************************\n") index = index + 1 if index == 1: print("***沒有任務須要執行***") scheduler.start()