python實(shí)現(xiàn)微信自動(dòng)回復(fù)及批量添加好友功能
先給大家介紹下python微信自動(dòng)回復(fù)功能
1.當(dāng)收到好友消息時(shí),自動(dòng)回復(fù)
import random
import itchat
import requests
import time
def get_tuling_response(_info):
print(_info)
# 圖靈機(jī)器人的網(wǎng)址
api_url = "http://www.tuling123.com/openapi/api"
data = {
'key': '5ea0f11b5b6146239c52a47849387484',
'info': _info,
'userid':'wechat-robot'
}
# 發(fā)送數(shù)據(jù)到指定網(wǎng)址,獲取網(wǎng)址返回的數(shù)據(jù)(字典數(shù)據(jù)類型)
res = requests.post(api_url, data).json()
# print(res, type(res))
# 給用戶返回的內(nèi)容
print(res['text'])
return res['text']
# 時(shí)刻監(jiān)控好友發(fā)送的文本消息, 并且給予一個(gè)回復(fù),
# isGroupChat=True接收群聊消息中的文本信息, 并讓圖靈機(jī)器人自動(dòng)回復(fù);
# isMapChat=True接收群聊消息中的文本信息, 并讓圖靈機(jī)器人自動(dòng)回復(fù);
@itchat.msg_register(itchat.content.TEXT, isFriendChat=True)
def text_reply(msg):
# 需求: 只對固定的群聊消息, 實(shí)現(xiàn)機(jī)器人聊天.
# 獲取好友發(fā)送消息的內(nèi)容
ps:下面介紹下python 批量生成微信添加好友截圖
# -*- coding: utf-8 -*-
import time,random,os
import PIL.Image as Image
import PIL.ImageColor as ImageColor
import PIL.ImageDraw as ImageDraw
import PIL.ImageFont as ImageFont
# from PIL import Image, ImageDraw
"""
author@:xiaohe
QQ496631085
python3.7
"""
def circle_corner(img, radii):
"""
圓角處理
:param img: 源圖象。
:param radii: 半徑,如:30。
:return: 返回一個(gè)圓角處理后的圖象。
"""
# 畫圓(用于分離4個(gè)角)
circle = Image.new('L', (radii * 2, radii * 2), 0) # 創(chuàng)建一個(gè)黑色背景的畫布
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, radii * 2, radii * 2), fill=255) # 畫白色圓形
# 原圖
img = img.convert("RGBA")
w, h = img.size
# 畫4個(gè)角(將整圓分離為4個(gè)部分)
alpha = Image.new('L', img.size, 255)
alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0)) # 左上角
alpha.paste(circle.crop((radii, 0, radii * 2, radii)), (w - radii, 0)) # 右上角
alpha.paste(circle.crop((radii, radii, radii * 2, radii * 2)), (w - radii, h - radii)) # 右下角
alpha.paste(circle.crop((0, radii, radii, radii * 2)), (0, h - radii)) # 左下角
# alpha.show()
img.putalpha(alpha) # 白色區(qū)域透明可見,黑色區(qū)域不可見
return img
#對象,位置 字體 字體大小 字體顏色 添加內(nèi)容
def imgAddFont(im1,gps,font,fontSize,fontColor,data):
# 在圖片上添加文字 1
draw = ImageDraw.Draw(im1)
#設(shè)置字體
time_font = ImageFont.truetype(font, fontSize)
# (0,0):坐標(biāo) "內(nèi)容":添加的字體 (0,0,255):字體顏色 font:字體大小
draw.text(gps,data,fontColor,font=time_font)
draw = ImageDraw.Draw(im1)
def copy(h,m,z,n,v):
#手機(jī)當(dāng)前時(shí)間 系統(tǒng)時(shí)間
systime = str(h) + ":"+str(m)
#小時(shí)隨便減去多少
add_h=random.randint(2,5)
#分鐘隨便減去多少
add_m=random.randint(2,7)
#添加好友的時(shí)間
addtime = str(h-add_h) + ":"+str(m-add_m)
#標(biāo)題名稱
# qun_name = "電銷 " + n
qun_name = n
#電池電量
diannum = str(v)
#打開圖片
im1=Image.open("new.png")
#系統(tǒng)時(shí)間 (寬 高)
imgAddFont(im1,(17,20),'C:\Windows\Fonts\msyh.ttc',38,(50,50,50),systime)
#電池電量
imgAddFont(im1,(1012,21),'C:\Windows\Fonts\simhei.ttf',29,(50,50,50),diannum)
#群姓名
imgAddFont(im1,(120,108),'C:\Windows\Fonts\msyh.ttc',49,(50,50,50),qun_name)
#添加時(shí)間
imgAddFont(im1,(490,260),'C:\Windows\Fonts\msyh.ttc',38,(170,170,170),addtime)
# #發(fā)消息時(shí)間
# imgAddFont(im1,(490,260),'C:\Windows\Fonts\msyh.ttc',38,(170,170,170),addtime)
# 保存位置 22 370
# img=im1
# 已經(jīng)添加好完整的文字了,下面添加圖片 打開 縮略 圓角 合并
# 打開頭像原圖檢測是否存在不存在就換個(gè)后綴
jpg_path = '.\\img\\' + (str(z))
if os.path.exists(jpg_path+".jpg"):
img = Image.open(jpg_path+".jpg")
else:
img = Image.open(jpg_path+".png")
img = circle_corner(img, radii=20)
#縮放等比例的尺寸
w, h = img.size
img.thumbnail((118, 118)) # 尺寸等比縮放
# 打開底圖
layer = Image.new('RGBA', im1.size, (0,0,0,0))
layer.paste(img, (20, 370))
out=Image.composite(layer,im1,layer)
# out.save("target.png")
save_time=time.strftime('%Y_%m_%d_%M_%H',time.localtime(time.time()))
out.save(save_time +str(z)+".png")
# out.save("target.png")
h=int(input("請輸入手機(jī)幾點(diǎn)"))
m=int(input("請輸入現(xiàn)在幾分"))
v=int(input("請輸入現(xiàn)在電量"))
z=int(input("請輸入需要生成多少張圖片"))
for x in range(1,z+1):
n=input("請輸入標(biāo)題昵稱 例如好友")
copy(h,m,x,n,v)
總結(jié)
以上所述是小編給大家介紹的python實(shí)現(xiàn)微信自動(dòng)回復(fù)及批量添加好友功能 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
用Python實(shí)現(xiàn)一個(gè)打字速度測試工具來測試你的手速
有很多小伙伴們都苦惱自己手速不夠,今天特地整理了這篇文章,教你用Python實(shí)現(xiàn)一個(gè)打字測試工具來測試你的打字速度,文中有非常詳細(xì)的代碼示例,對想練手速的小伙伴們很有用哦,需要的朋友可以參考下2021-05-05
Pytorch使用技巧之Dataloader中的collate_fn參數(shù)詳析
collate_fn 參數(shù)的目的主要是為了隨心所欲的轉(zhuǎn)變數(shù)據(jù)的類型,這個(gè)數(shù)據(jù)是用DataLoader加載的,比如img,target,下面這篇文章主要給大家介紹了關(guān)于Pytorch使用技巧之Dataloader中的collate_fn參數(shù)的相關(guān)資料,需要的朋友可以參考下2022-03-03
python網(wǎng)絡(luò)爬蟲采集聯(lián)想詞示例
這篇文章主要介紹了python網(wǎng)絡(luò)爬蟲采集聯(lián)想詞示例,需要的朋友可以參考下2014-02-02
Python實(shí)現(xiàn)查找字符串?dāng)?shù)組最長公共前綴示例
這篇文章主要介紹了Python實(shí)現(xiàn)查找字符串?dāng)?shù)組最長公共前綴,涉及Python針對字符串的遍歷、判斷、計(jì)算等相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
解決pycharm無法識別本地site-packages的問題
今天小編就為大家分享一篇解決pycharm無法識別本地site-packages的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10
Python實(shí)現(xiàn)的多進(jìn)程拷貝文件并顯示百分比功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)的多進(jìn)程拷貝文件并顯示百分比功能,涉及Python多進(jìn)程、文件遍歷、拷貝等相關(guān)操作技巧,需要的朋友可以參考下2019-04-04
Python多維/嵌套字典數(shù)據(jù)無限遍歷的實(shí)現(xiàn)
下面小編就為大家?guī)硪黄狿ython多維/嵌套字典數(shù)據(jù)無限遍歷的實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11
python+mongodb數(shù)據(jù)抓取詳細(xì)介紹
這篇文章主要介紹了python+mongodb數(shù)據(jù)抓取詳細(xì)介紹,具有一定參考價(jià)值,需要的朋友可以了解下。2017-10-10

