十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專(zhuān)業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wè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è)是用來(lái)讀Excel文件的工具。
3,apscheduler:這個(gè)是用來(lái)定時(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("***沒(méi)有任務(wù)需要執(zhí)行***")
scheduler.start()