求助wxpy 下载附件时 文件为0字节
import itchat
import time
import os
import colorama
from colorama import init,Fore,Back,Style
init(autoreset=True)
import re
from wxpy import *
import winsound
import threading
import xlrd
from xlrd import xldate_as_tuple
import datetime
SourceSavePath = 'D:\\liuying\\work\\RecieveFile\\'
SourceSavePath2 = 'D:/liuying/work/RecieveFile/'
BJTM = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
bot = Bot(cache_path=True,console_qr=False)
bot.enable_puid(path=r'D:\liuying\work\qh\wxpy_puid.pkl')
bot.auto_mark_as_read
bot.friends(update=False)
bot.groups(update=False)
ceshiqun = "测试"
weixinqun0 = "信息汇总"
namejs = 'A刘英'
mywx = bot.friends().search(namejs)[0]
myFriend = bot.friends()
mywxQun = bot.groups()
@bot.register(myFriend)
def myFriend(msg):
aa =time.time()
BJTMS = msg.create_time
if msg.type == TEXT:
j = msg.text
j = j.replace(" ","").replace("\r\n","").replace("\n","").replace("-","").replace("_","").replace("\t","")
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+str(msg).split(':')[0]+'\n'+j)
elif msg.type == PICTURE:
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+str(msg).split(':')[0]+'发了图片')
elif msg.type == RECORDING:
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+str(msg).split(':')[0]+'发了语音')
elif msg.type == ATTACHMENT:
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+str(msg).split(':')[0]+'发了文件')
elif msg.type == VIDEO:
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+str(msg).split(':')[0]+'发了视频')
else:
print('\n',BJTMS,'\t延时',str(time.time()-aa),'秒显示\n\033[1;34;44m☆☆:',msg)
@bot.register(mywxQun)
def mywxQun(msg):
aa =time.time()
BJTMS = msg.create_time
qunname = str(msg).split('›')[0]
qunname = qunname.replace(" ","").replace("\r\n","").replace("\n","").replace("-","").replace("_","").replace("\t","")
qunpop = str(msg).split('›')[1].split(':')[0]
try:
Pathname = format(msg.file_name)
except:
pass
if qunname == ceshiqun or qunname == weixinqun0 :
if msg.type == TEXT:
j = msg.text
j = j.replace(" ","").replace("\r\n","").replace("\n","").replace("-","").replace("_","").replace("\t","")
print('\n',BJTMS,'\t延时',str(time.time()-aa),'秒显示\n\033[1;37;44m ☆ '+qunname,' ☆ ','\033[1;37;44m'+qunpop,'\033[1;32;40m发来信息\033[0m\n\t信息内容 : ☆ ','\033[1;37;40m'+j)
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+qunname+'\n'+qunpop+'\n'+j)
xinjianpath = SourceSavePath2+qunname
try:
os.makedirs(xinjianpath)
except:
pass
logtxt = open(SourceSavePath +qunname+'\\'+"log.txt", "a",encoding='utf-8')
logtxt.writelines(str(BJTMS)+' '+qunname+' '+qunpop+j+'\n')
logtxt.close()
elif msg.type == PICTURE:
print('\n',BJTMS,'\t延时',str(time.time()-aa),'秒显示\n\033[1;37;44m ☆ ',qunname,' ☆ ','\033[1;37;44m'+qunpop,'\033[1;37;40m发来图片:',Pathname)
PICPath = SourceSavePath +qunname+'\\'+ Pathname
xinjianpath = SourceSavePath2+qunname
try:
os.makedirs(xinjianpath)
except:
pass
msg.get_file(PICPath)
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+qunname+'\n'+qunpop+'\n发了图片')
logtxt = open(SourceSavePath +qunname+'\\'+"log.txt", "a",encoding='utf-8')
logtxt.writelines(str(BJTMS)+' '+qunname+' '+qunpop+' 发了图片 '+Pathname+'\n')
logtxt.close()
bot.friends().search(namejs)[0].send_file(PICPath)
elif msg.type == RECORDING:
print('\n',BJTMS,'\t延时',str(time.time()-aa),'秒显示\n\033[1;37;44m ☆ ',qunname,' ☆ ','\033[1;37;44m'+qunpop,'\033[1;32;40m发来语音:',Pathname)
RECPath = SourceSavePath +qunname+'\\'+ Pathname
xinjianpath = SourceSavePath2+qunname
try:
os.makedirs(xinjianpath)
except:
pass
msg.get_file(RECPath)
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+qunname+'\n'+qunpop+'\n发了语音 ')
logtxt = open(SourceSavePath +qunname+'\\'+"log.txt", "a",encoding='utf-8')
logtxt.writelines(str(BJTMS)+' '+qunname+' '+qunpop+' 发了语音 '+Pathname+'\n')
logtxt.close()
bot.friends().search(namejs)[0].send_file(RECPath)
elif msg.type == ATTACHMENT:
print('\n',BJTMS,'\t延时',str(time.time()-aa),'秒显示\n\033[1;37;44m ☆ ',qunname,' ☆ ','\033[1;37;44m'+qunpop,'\033[1;32;40m发来文件:',Pathname)
ATTPath = SourceSavePath +qunname+'\\'+ Pathname
xinjianpath = SourceSavePath2+qunname
try:
os.makedirs(xinjianpath)
except:
pass
msg.get_file(ATTPath)
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+qunname+'\n'+qunpop+'\n发了文件 '+Pathname)
logtxt = open(SourceSavePath +qunname+'\\'+"log.txt", "a",encoding='utf-8')
logtxt.writelines(str(BJTMS)+' '+qunname+' '+qunpop+' 发了文件 '+Pathname+'\n')
logtxt.close()
bot.friends().search(namejs)[0].send_file(ATTPath)
elif msg.type == VIDEO:
print('\n',BJTMS,'\t延时',str(time.time()-aa),'秒显示\n\033[1;37;44m ☆ ',qunname,' ☆ ','\033[1;37;44m'+qunpop,'\033[1;32;40m发来视频:',Pathname)
VIDsavaPath = SourceSavePath +qunname+'\\'+ Pathname
xinjianpath = SourceSavePath2+qunname
try:
os.makedirs(xinjianpath)
except:
pass
msg.get_file(VIDsavaPath)
bot.friends().search(namejs)[0].send(str(BJTMS)+'\n'+qunname+'\n'+qunpop+'\n发了视频 ')
logtxt = open(SourceSavePath +qunname+'\\'+"log.txt", "a",encoding='utf-8')
logtxt.writelines(str(BJTMS)+' '+qunname+' '+qunpop+' 发了视频 '+Pathname+'\n')
logtxt.close()
bot.friends().search(namejs)[0].send_file(VIDsavaPath)
else:
print('\n',BJTMS,'\t延时',str(time.time()-aa),'秒显示\n\033[1;37;44m ☆ ',msg)
embed()