一、簡(jiǎn)介
1,使用微信,定時(shí)往指定的微信群里發(fā)送指定信息。
2,需要發(fā)送的內(nèi)容使用excel進(jìn)行維護(hù),指定要發(fā)送的微信群名、時(shí)間、內(nèi)容。
二、py庫(kù)
1,itchat:這個(gè)是主要的工具,用于連接微信個(gè)人賬號(hào)接口。以下是一些相關(guān)的知識(shí)點(diǎn)網(wǎng)站。
2,xlrd:這個(gè)是用來讀Excel文件的工具。
3,apscheduler:這個(gè)是用來定時(shí)調(diào)度時(shí)間的工具。
三、實(shí)例代碼
# 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("發(fā)送時(shí)間:" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n" "發(fā)送到:" + name + "\n" "發(fā)送內(nèi)容:" + 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("任務(wù)" + str(index) + ":\n" "待發(fā)送時(shí)間:" + date_value + "\n" "待發(fā)送到:" + name + "\n" "待發(fā)送內(nèi)容:" + context + "\n" "******************************************************************************\n") index = index + 1 if index == 1: print("***沒有任務(wù)需要執(zhí)行***") scheduler.start()
總結(jié)
以上所述是小編給大家介紹的Python3 itchat實(shí)現(xiàn)微信定時(shí)發(fā)送群消息的實(shí)例代碼 ,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
