求助wxpy 下载附件时 文件为0字节

1 篇文章 0 订阅

求助wxpy 下载附件时 文件为0字节

# -*- coding:utf-8 -*-

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

#winsound.Beep(500,1000)
#winsound.PlaySound(r"D:\liuying\work\qh\Yes.wav", winsound.SND_FILENAME)
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
#moshi = input(u'\n\t\t是否更新用户信息 "n" or "y" and "Enter":\n')
#if moshi == "y" or moshi == "" : 
#    bot.friends(update=False)
#    bot.groups(update=False)
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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值