Python-itchat獲取微信好友信息

參考自:http://www.lxweimin.com/p/684cbdf15874
思路就是通過itchat登錄獲取微信好友信息,然后通過pillow畫圖

import itchat
import math
import PIL.Image as Image
import os
# hotReload=True  # 使用這個屬性,生成一個靜態文件itchat.pkl,用于存儲登陸的狀態。
itchat.auto_login(hotReload=True)
friends = itchat.get_friends(update=True)[0:]
path = 'G:/python/image/'
for item in friends:
    # 可以打印item來看其中具體是什么內容,有什么字段
    img = itchat.get_head_img(userName=item['UserName'])
    with open(path + item['NickName'] + '.jpg', 'wb') as f:
        f.write(img)
# 獲取好友昵稱和簽名
info = [(item['NickName'], item['Signature']) for item in friends]
# 獲取文件夾中所有的圖片
ls = os.listdir(path)
img_num = len(ls)
# 每張小圖片寬
size = 60
#每行放幾張
lines = 10
# 大圖寬
width = 600
# 大圖長
height = math.ceil(img_num/10)*60
# 畫一個大圖,用來放小頭像
image = Image.new('RGBA', (width, height))
x = 0
y = 0
for i in range(0, len(ls)):
    img = Image.open(path + info[i][0] + '.jpg')
    img = img.resize((size, size), Image.ANTIALIAS)
    # 向指定位置放縮小后的圖片
    image.paste(img, (x * size, y * size))
    x += 1
    if x == lines:
        x = 0
        y += 1
image.save(path + 'friends.jpg')
# 通過文件助手發給自己
itchat.send_image(path + 'friends.jpg', 'filehelper')
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容