Git address
Weird uncle selling nuts
The preparatory work
1. A wechat signal to log in to the web version of wechat
2. An IDE editor
The Python environment is based on Python3
Installation-dependent dependencies
The ability to log in to wechat mainly depends on the Python library wxpy
Introduce the Python OS library
from wxpy import *
import os
Copy the code
The main code
Create avatars folder
def create_file_path():
avater_dir = os.path.join(os.getcwd(),'wechat')
if not os.path.exists(avater_dir):
os.mkdir(avater_dir)
return avater_dir
Get all your friends' avatars and save them
def save_wx_avater(avater_dir):
bot = Bot(cache_path=True)
friends = bot.friends(update=True)
num = 0
nameList = []
for friend in friends:
# Save the profile picture to the specified folder
friend.get_avatar(os.path.join(avater_dir,f'{str(friend.name)}.jpg'))
nameList.append(friend.name)
print("Friend nickname: %s"%friend.name)
num += 1
# go through the nickname list and write TXT
with open('wechat friend nicknames. TXT'.'w+', encoding='utf-8')as f:
for n in nameList:
f.write("'"+n+"',\n")
f.close()
print("End of procedure:")
print(nameList)
Copy the code
Execute a program
if __name__ == '__main__':
avatar_dir = create_file_path()
save_wx_avater(avatar_dir)
Copy the code