日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python代码练习,微信登入并生成头像大图

發(fā)布時(shí)間:2023/12/8 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python代码练习,微信登入并生成头像大图 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
import itchat import os from math import sqrt from PIL import Image import shutilpwd = os.getcwd() #獲取相對路徑 print(pwd) filename = pwd +'\\'+'weixin' #存放圖片路徑 print(filename) if not os.path.exists(filename): #判斷是否有文件夾os.makedirs(filename)print('文件夾已新建') else:print('文件夾已存在')itchat.auto_login() #微信登入 friends = itchat.get_friends(update=True)[0:] itchat.send('歡迎光臨,正在為您生成圖片', 'filehelper') for item in friends: #開始下載圖片print ('正在下載 '+item['NickName']+' 的圖片')img = itchat.get_head_img(userName=item["UserName"])path = filename+'\\'+item['NickName']+'.jpg'try:with open(path,'wb') as f:f.write(img)except Exception as e:print(repr(e)) user = friends[0]['UserName'] pathList = [] for item in os.listdir(filename): imgPath = os.path.join(filename,item) #讀取圖片pathList.append(imgPath) total = len(pathList) #total是好友頭像圖片總數(shù) line = int(sqrt(total)) #line是拼接圖片的行數(shù)(即每一行包含的圖片數(shù)量) NewImage = Image.new('RGB', (128*line,128*line)) x = y = 0 for item in pathList:try:img = Image.open(item)img = img.resize((128,128),Image.ANTIALIAS)NewImage.paste(img, (x * 128 , y * 128))x += 1except IOError:print("第%d行,%d列文件讀取失敗!IOError:%s" % (y,x,item))x -= 1if x == line:x = 0y += 1if (x+line*y) == line*line:break NewImage.save(filename+'\\'+user+'.jpg') itchat.send_image(filename+'\\'+user+'.jpg', 'filehelper') #發(fā)送圖片到文件助手 itchat.send('圖片生成成功', 'filehelper') shutil.rmtree(filename) #刪除文件夾 itchat.logout()

網(wǎng)上有很多類似的代碼,吵吵改改,自己寫的勿噴,代碼練習(xí)中
有個(gè)問題itchat的登入二維碼會(huì)在程序關(guān)閉后還會(huì)彈出來有什么解決辦法嗎

總結(jié)

以上是生活随笔為你收集整理的python代码练习,微信登入并生成头像大图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。