python實(shí)現(xiàn)微信自動回復(fù)及批量添加好友功能
先給大家介紹下python微信自動回復(fù)功能
1.當(dāng)收到好友消息時(shí),自動回復(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ī)器人自動回復(fù); # isMapChat=True接收群聊消息中的文本信息, 并讓圖靈機(jī)器人自動回復(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)微信自動回復(fù)及批量添加好友功能 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
python GUI庫圖形界面開發(fā)之PyQt5狀態(tài)欄控件QStatusBar詳細(xì)使用方法實(shí)例
這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5狀態(tài)欄控件QStatusBar詳細(xì)使用方法實(shí)例,需要的朋友可以參考下2020-02-02基于Python和Scikit-Learn的機(jī)器學(xué)習(xí)探索
這篇文章主要介紹了基于Python和Scikit-Learn的機(jī)器學(xué)習(xí)探索的相關(guān)內(nèi)容,小編覺得還是挺不錯(cuò)的,這里分享給大家,供需要的朋友學(xué)習(xí)和參考。2017-10-10python 回調(diào)函數(shù)和回調(diào)方法的實(shí)現(xiàn)分析
這篇文章主要介紹了python 回調(diào)函數(shù)和回調(diào)方法的實(shí)現(xiàn)分析,需要的朋友可以參考下2016-03-03python自定義函數(shù)def的應(yīng)用詳解
這篇文章主要介紹了python自定義函數(shù)def的應(yīng)用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06使用Python爬了4400條淘寶商品數(shù)據(jù),竟發(fā)現(xiàn)了這些“潛規(guī)則”
這篇文章主要介紹了使用Python爬了4400條淘寶商品數(shù)據(jù),竟發(fā)現(xiàn)了這些“潛規(guī)則”,筆者用 Python 爬取淘寶某商品的全過程,并對商品數(shù)據(jù)進(jìn)行了挖掘與分析,最終得出結(jié)論。需要的朋友可以參考下2018-03-03