Python|每日定时对指定好友发送随机消息~
2020-12-13 05:50
标签:sleep split hat use friend cep dom 随机 用户 代码很简单,直接贴了: 一共需要要三次输入,前俩次为中文输入法输入,第三次用英文输入法输入(用‘:‘分隔) Python|每日定时对指定好友发送随机消息~ 标签:sleep split hat use friend cep dom 随机 用户 原文地址:https://www.cnblogs.com/huhahuhahu/p/11151328.htmlimport itchat
import datetime
import time
import random
def wenhouyu(a):
i = random.choice(a)
return i
itchat.auto_login(hotReload=True)
names = input(‘请输入接收者微信昵称,多个用户用逗号隔开‘+‘\n‘).split(‘,‘)
whlist = input(‘请输入问候语,多条语句请用分号隔开,每次会随机发送其中一条‘+‘\n‘).split(‘;‘)
Time = input(‘请输入发送时间,如:08:30:00(英文输入法输入)‘+‘\n‘)
print(names)
print(whlist)
print(Time)
while 1:
now = datetime.datetime.now()
now_str = now.strftime(‘%Y/%m/%d %H:%M:%S‘)[11:]
print(‘\r{}‘.format(now_str))
if now_str in [Time]:
print(‘1‘*50)
wh = wenhouyu(whlist)
for friend in names:
try:
name1 = itchat.search_friends(name=friend)
userName = name1[0][‘UserName‘]
itchat.send(wh ,toUserName=userName) #发送整理出的消息
print(‘已向‘+friend+‘发送消息:‘+wh)
except:
print(‘2‘*50)
time.sleep(1)