1,使用微信,定時(shí)往指定的微信群里發(fā)送指定信息。
2,需要發(fā)送的內(nèi)容使用excel進(jìn)行維護(hù),指定要發(fā)送的微信群名、時(shí)間、內(nèi)容。
二、py庫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()
文章名稱:Python3itchat實(shí)現(xiàn)微信定時(shí)發(fā)送群消息的實(shí)例代碼-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://aaarwkj.com/article14/ccjgge.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、網(wǎng)站建設(shè)、App設(shè)計(jì)、云服務(wù)器、網(wǎng)站營(yíng)銷、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容