from wxpy import *
from time import sleep
import random
bot = Bot(cache_path= True)
#print('防止微信賬號違規操作被封,每次發送信息時間間隔為隨機0-1.5s')
message = input('請輸入要發送的微信信息:')
friends_number = input('請輸入賬號好友數量:')
number = int(friends_number)
accord = input('輸入符合條件人的關鍵字(如要發送全部好友,請輸入all):')
accordint= str(accord)
for i in range(0, number):
try:
my_friend = bot.friends(update=True).search()[i]
except Exception as b:
print('好友沒有uid或查找好友超過索引數')
else:
print(my_friend)
people = str(my_friend)
if accordint in people:#如果備注信息包含你輸入的文字
try:
print('找到符合要求的好友')#打印好友備注
my_friend.send(message)#發送信息
except Exception as a:#如果執行出錯
print("不是您的好友或不存在該好友")
else:
print('發送信息成功')
loadtime = random.uniform(0.5, 1.5)
sleep(loadtime)
print(loadtime)
#try執行成功
if accordint == 'all':#如果備注信息包含你輸入的文字
try:
print(my_friend)#打印好友備注
my_friend.send(message)#發送信息
except Exception as a:#如果執行出錯
print("好友不是您的好友或不存在該好友")
else:
print('發送信息成功')#try執行成功
print('已完成')
bot.logout()
bot.join()