吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3267|回复: 16
收起左侧

[Python 转载] 微信批量上传文件程序【更新一下效果图】

  [复制链接]
话痨司机啊 发表于 2022-5-16 14:42
本帖最后由 话痨司机啊 于 2022-5-25 20:32 编辑

【源码下载地址】链接: https://pan.baidu.com/s/1lNZ6Cns3oWPhQuCiTpCMaw?pwd=en25 提取码: en25
成品exe下载地址】链接: https://pan.baidu.com/s/1Va1Pz-Ue2Jq815BjpuvUig?pwd=vsb2 提取码: vsb2
【演示说明下载地址】链接: https://pan.baidu.com/s/1AtNzUuquaXsLPFdk_NR8bw?pwd=hxpb 提取码: hxpb


【说明】 运行程序之前需要打开PC端微信并登录,配置好配置文件,如果下载成品的,运行一次配置文件就自动生成了,这时候你可以自定义上传文件夹,默认的是桌面的uploads(如果没有,请自行新建文件夹并命名uploads,将需要上传的文件放到uploads)。
2.jpg

核心代码:
核心代码.png

[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
        ************************************
          Description:  文件批量上传到微信
          Author: @话痨
          Github: [url=https://github.com/jianala]https://github.com/jianala[/url]
          Date: 2022-05-16 10:35:09
          FilePath: \电脑操控类\wetchat_uploads.py
          LastEditors: @话痨
          LastEditTime: 2022-05-16 10:36:58
          善始者实繁,克终者盖寡。
        ************************************
"""
 
 
import logging
import os
import subprocess
from functools import wraps
import time
import uiautomation as auto
from rich.console import Console
from configparefile import ConfigFile
 
logging.basicConfig(level=logging.INFO,
                    filename='wetchat_uploads.log',
                    filemode='a',
                    format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S')
 
 
def exception_handler(func):
    """
        description: 异常捕获装饰器
        return {函数调用返回值}}   
    """
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            logging.error(e)
    return wrapper
 
 
def is_configfile_exists():
    """
        description: 判断配置文件是否存在,不存在则创建并写入配置文件
    """
    _cfg = ConfigFile('wechat_config.ini')
    if not _cfg.is_file_exist():
        _cfg.set_config('WeChat_path', 'file_path',
                        'C:\\Program Files\\Tencent\\WeChat\\WeChat.exe')
        _cfg.set_config('uploads_path', 'dir_path',
                        'C:\\Users\\Administrator\\Desktop\\uploads')
 
 
class WechatUploads:
    def __init__(self) -> None:
        self.wx = auto.WindowControl(Name='微信')
        self.cgf = ConfigFile('wechat_config.ini')
        self.console = Console()
        self.dir_uploads = os.path.normpath(
            self.cgf.read_config()['uploads_path']['dir_path'])
        print(
            """
        ************************************\r\n
  
          _______________#########_______________________
          ______________############_____________________
          ______________#############____________________
          _____________##__###########___________________
          ____________###__######_#####__________________
          ____________###_#######___####_________________
          ___________###__##########_####________________
          __________####__###########_####_______________
          ________#####___###########__#####_____________
          _______######___###_########___#####___________
          _______#####___###___########___######_________
          ______######___###__###########___######_______
          _____######___####_##############__######______
          ____#######__#####################_#######_____
          ____#######__##############################____
          ___#######__######_#################_#######___
          ___#######__######_######_#########___######___
          ___#######____##__######___######_____######___
          ___#######________######____#####_____#####____
          ____######________#####_____#####_____####_____
          _____#####________####______#####_____###______
          ______#####______;###________###______#________
          ________##_______####________####______________
 
        ************************************ \r\n
 
    -*-批量上传微信文件-*-
"""
        )
 
    @exception_handler
    def is_WeChat_start(self):
        """
            description: 判断微信是否启动,如果启动则为真,否则调用微信
            return {*}
        """
        if self.wx.Exists():
            self.wx.SwitchToThisWindow()
            logging.info('微信已经启动')
            return True
        else:
            subprocess.Popen(self.cgf.read_config().get(
                'WeChat_path', 'file_path'))
            raise Exception('微信未启动,请启动微信后再次运行该程序!')
 
    @exception_handler
    def get_file_list(self, path):
        """
        description: 获取文件夹的文件列表
        return {*}
        """
        file_list = []
        for root, dirs, files in os.walk(path):
            for file in files:
                file_list.append(os.path.join(root, file))
        return file_list
 
    @exception_handler
    def upload_target(self, upload_target):
        """
            description: 判断上传目标是存在
            params: upload_target {str} 上传目标
            return {*}
        """
        hh = self.wx.ListControl(name='会话').GetChildren()
        for h in hh:
            if h.Name == upload_target:
                return upload_target
        raise Exception('上传目标不存在')
 
    def wechat_api(self, file_name, target):
        """
                 description: 上传接口
                 return {*}
        """
        self.wx.ListItemControl(Name=target).Click(simulateMove=False)
        self.wx.ButtonControl(Name='发送文件').Click(simulateMove=False)
        self.wx.EditControl(Name='文件名(N):').SendKeys(file_name)
        self.wx.SplitButtonControl(Name='打开(O)').Click(simulateMove=False)
        self.wx.ButtonControl(Name='sendBtn').Click(simulateMove=False)
 
    # 调用微信上传文件
    def upload_file(self, upload_target):
        """
                 description: 上传文件
                 return {*}
        """
        if self.is_WeChat_start():
            _upload_target = self.upload_target(upload_target)
            _file_list = self.get_file_list(self.dir_uploads)
            for _file in _file_list:
                self.wechat_api(_file, _upload_target)
                now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
                self.console.print("[yellow]创建时间:{}\n文件:{} [green]状态:上传成功!".format(now, os.path.basename(_file)))
                logging.info('{}上传成功'.format(_file))
 
 
if __name__ == "__main__":
    is_configfile_exists()
    wx = WechatUploads()
    target = input('请输入上传目标(直接回车就默认为文件传输助手):').strip()
    target = target if not target == '' else '文件传输助手'
    wx.upload_file(target)
    


运行效果反馈,已经测试一周了,稳定运行,虚拟机 每天晚上7点55分开机,然后7点57分自动登录微信,8点整发送文件和发送信息提醒群内人员收听并通过钉钉机器人反馈发送情况,剩余文件等信息,8点02分虚拟机关机(当然为了不发送重复文件还将发送的文件移除到另一个文件夹以后待用)。
QQ图片20220525202705.png

免费评分

参与人数 6吾爱币 +4 热心值 +4 收起 理由
yanglinman + 1 谢谢@Thanks!
jamessteed + 1 + 1 谢谢@Thanks!
Atnil + 1 谢谢@Thanks!
FENGyongtang + 1 我很赞同!
wapj152321 + 1 + 1 我很赞同!
S1280P + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

MillaN 发表于 2022-5-16 14:58
好牛,顶顶。顺便问问这个的应用场景是啥
 楼主| 话痨司机啊 发表于 2022-5-16 19:26
MillaN 发表于 2022-5-16 14:59
我每次很多文件都是直接批量CTRL+V

我记得一次复制不能超过9个以上的文件,我这个可以把文件夹里的所有文件上传
TZSJ 发表于 2022-5-16 14:57
MillaN 发表于 2022-5-16 14:59
我每次很多文件都是直接批量CTRL+V
十二三i 发表于 2022-5-16 15:07
感谢分享
zixudaoxian 发表于 2022-5-16 15:27
初音很可以,加大力度!
iawyxkdn8 发表于 2022-5-16 15:51
看上去挺好的,就是我这破电脑,XP系统用不了!
不忘形影 发表于 2022-5-16 16:04
用在什么场合
孤舟垂钓者 发表于 2022-5-16 16:18

感谢分享
 楼主| 话痨司机啊 发表于 2022-5-16 17:32

定时任务
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-9-23 09:21

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表