前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[python][企业微信]企业微信自动打卡Python脚本,价值一万元的自动打卡脚本

[python][企业微信]企业微信自动打卡Python脚本,价值一万元的自动打卡脚本

作者头像
landv
发布2020-05-12 17:12:45
3.9K0
发布2020-05-12 17:12:45
举报
文章被收录于专栏:landvlandv
代码语言:javascript
复制
# -*- coding: utf-8 -*-
import datetime
import os
import random
import time
import schedule
# 引入uiautomator库
from pip._vendor import requests
from uiautomator import device as d

# 法定节假日准确日期,不进行打卡
holiday = ['2020-06-25',
           '2020-06-26',
           '2020-06-27',
           '2020-10-01',
           '2020-10-02',
           '2020-10-03',
           '2020-10-04',
           '2020-10-05',
           '2020-10-06',
           '2020-10-07',
           '2020-10-08',
           ]
# 调整工作日准确日期,进行打卡
ajustWorking = ['2020-05-09', '2020-06-28', '2020-09-27', '2020-10-10']
# 调休日期,不进行打卡
compensatoryLeave = ['2020-05-16']


def init():
    # 初始化信息
    print(d.info)
    # 点亮屏幕
    # d.screen.on()
    os.popen("adb shell input keyevent 224")
    time.sleep(1)
    # 滑动屏幕
    os.popen("adb shell input swipe 300 2000 300 500")
    time.sleep(1)
    # 输入密码
    os.popen("adb shell input text 密码")  # 你的手机密码
    time.sleep(1)


def openwework():
    """
    企业微信打卡
    clock in out 上班 下班
    :return:
    """
    init()
    msg = 0
    # 先结束再开启
    os.popen("adb shell am force-stop com.tencent.wework")
    time.sleep(1)
    os.popen("adb shell am start com.tencent.wework/com.tencent.wework.launch.LaunchSplashActivity")
    time.sleep(5)
    print("启动企业微信成功")
    d(text=u"工作台").click()
    time.sleep(1)
    d(text=u"打卡").click()
    time.sleep(3)
    print("打开打卡界面成功")
    print("当前小时:", datetime.datetime.now().hour)

    if datetime.datetime.now().hour < 11:
        # 早晨卡
        if d(text=u"你已在打卡范围内").info['text'] == "你已在打卡范围内":
            print("现在是上午")
            d(text=u"上班打卡").click()
            time.sleep(2)
            if d(text=u"上班·正常").info['text'] == "上班·正常":
                in_time = d(className="android.widget.TextView", resourceId="com.tencent.wework:id/mp").info['text']
                print("打卡时间:", in_time)
                msg = "上班打卡成功: 时间:" + in_time + " 日志时间:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            else:
                msg = "打卡失败:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    else:
        # 下班卡
        if d(text=u"你已在打卡范围内").info['text'] == "你已在打卡范围内":
            print("现在是下午")
            d(text=u"下班打卡").click()
            time.sleep(2)
            if d(text=u"下班·正常").info['text'] == "下班·正常":
                in_time = d(className="android.widget.TextView", resourceId="com.tencent.wework:id/mp").info['text']
                print("打卡时间:", in_time)
                msg = "下班打卡成功: 时间:" + in_time + " 日志时间:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            else:
                msg = "打卡失败:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # 返回桌面
    time.sleep(1)
    os.popen("adb shell input keyevent 3")
    time.sleep(1)
    os.popen("adb shell am force-stop com.tencent.wework")
    time.sleep(1)
    return msg


# 启动微信
def wexin():
    # 按home键
    os.popen("adb shell input keyevent 3")
    time.sleep(1)
    os.popen("adb shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI")
    time.sleep(3)
    print("启动微信成功")
    d(text=u"通讯录").click()
    time.sleep(1)
    d(text=u"你自己的微信名字").click()  # 你自己的微信名字  
    time.sleep(2)
    d(text=u"音视频通话").click()
    time.sleep(1)
    d(text=u"语音通话").click()
    # 振铃五秒钟
    time.sleep(5)
    # d(text=u"取消").click()
    os.popen("adb shell input tap 540 1850")
    time.sleep(3)
    # 按返回键
    os.popen("adb shell input keyevent 4")
    time.sleep(2)
    os.popen("adb shell input keyevent 4")
    time.sleep(1)
    # 按home键
    os.popen("adb shell input keyevent 3")
    time.sleep(1)
    os.popen("adb shell am force-stop com.tencent.mm")
    print("结束微信成功")
    time.sleep(1)
    # 锁屏
    os.popen("adb shell input keyevent 26")


def pushmsg(msg):
    """
    推送消息给微信
    :return:
    """
    try:
        url = 'http://wxpusher.zjiecode.com/api/send/message/?appToken=你自己的token&content=' + msg + '&uid=你自己的uid'
        requests.get(url)
    except Exception:
        print("推送消息异常")


def fuckCard():
    # 设置增加的随机分钟数
    clocknum = 3
    # 获取当前时间,2020-05-05 07:45
    nowtime = datetime.datetime.now()
    print("当前时间:", nowtime)
    # 加上随机数(0-3分钟),2020-05-05 07:46
    doworktime = (nowtime + datetime.timedelta(minutes=random.randint(0, clocknum))).strftime("%Y-%m-%d %H:%M")
    print("执行任务时间:", doworktime)
    a = 0
    # 如果当前时间小于执行时间,执行while循环
    while time.strftime("%Y-%m-%d %H:%M", time.localtime()) < doworktime:
        print("秒数:", a)
        a += 1
        time.sleep(1)
    # 到时间执行任务
    # 如果当前时间大于执行时间,执行任务
    if time.strftime("%Y-%m-%d %H:%M", time.localtime()) >= doworktime:
        print("到时间执行任务")
        msg = openwework()
        pushmsg(msg)
        wexin()
        return


def fuckRest():
    """
    # 搞定随机时间
    :return:
    """
    if time.strftime("%Y-%m-%d", time.localtime()) in holiday:
        print("今天是法定假日")
        return True
    if time.strftime("%Y-%m-%d", time.localtime()) in compensatoryLeave:
        print("今天是调休日期,不进行打卡~~")
        return True
    if time.strftime("%Y-%m-%d", time.localtime()) in ajustWorking:
        print("今天是调整工作日,需要进行打卡")
        # 周六启动计划任务问题,需要进行时间判断修复 schedule.every().saturday.at('12:09').do(fuckRest)
        # 也就是是避免 12点问题
        if datetime.datetime.now().hour != 12:
            print("调整工作日,早8八点,晚6点,正常打卡")
            fuckCard()
        return True

    # 判断是否为周一到周六上午
    # 1.判断当前日期是否为周日
    if datetime.datetime.now().weekday() != 6:
        if datetime.datetime.now().weekday() != 5:
            print("周一至周五")
            fuckCard()
        else:
            print("今天是周六")
            if (datetime.datetime.now().hour >= 8) and (datetime.datetime.now().hour < 13):
                print("周六半天打卡")
                fuckCard()



# 企业微信自动打卡
if __name__ == "__main__":
    '''
    主函数
    linux 后台运行
    nohup python3 -u main.py > main.log 2>&1 &
    Windows 
    start /b python3 main.py
    # 我司工作日:周一至周五,早8晚6。周六早8点半,中午12点。
    '''
    # 每天执行打卡
    # 第一个卡
    schedule.every().day.at('07:45').do(fuckRest)
    # # 周六执行此任务
    # 正常工作日周六早晨卡
    schedule.every().saturday.at('08:13').do(fuckRest)
    # 正常工作日周六中午卡
    schedule.every().saturday.at('12:09').do(fuckRest)
    # # 第二个卡
    schedule.every().day.at('18:11').do(fuckRest)
    while True:
        schedule.run_pending()
        time.sleep(3)

[python][企业微信]企业微信自动打卡Python脚本 价值一万元的自动打卡脚本

这个Python脚本还是有bug的,暂时不在维护和修复了,如果按照既定规划的执行不会出现错误。

当然,断网,断电,手机异常升级,重启等等错误,仍然需要人工进行搞定。

不过嘛,当没有收到提醒通知的时候,人工看看吧,也就早晨和下班那么一哆嗦,这要保证这一哆嗦不错误就好了。

反正我暂时没有遇见错误呢,遇见的时候再说吧,欢迎大家把错误信息发给我。

价值一万元的自动打卡脚本,表问我为毛价值一万元,你懂得,哇哈哈哈。

# 笔记相关

``` text # Android sdk tools /home/landv/Android/Sdk/tools/bin/uiautomatorviewer

# 启动微信 adb shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI # 杀死微信进程 adb shell am force-stop com.tencent.mm # 启动企业微信 adb shell am start com.tencent.wework/com.tencent.wework.launch.LaunchSplashActivity # 杀死企业微信进程 adb shell am force-stop com.tencent.wework # 加班休息扣除方式test adb shell am start com.tencent.wework/com.tencent.wework.enterprise.attendance.rule.TestExportActivity # 人脸信息 adb shell am start com.tencent.wework/com.tencent.wework.enterprise.attendance.controller.AttendanceFaceDetailActivity

#adb shell uiautomator 命令 uiautomator dump dump出当前窗口的UI布局信息 uiautomator dump --compressed dump出当前窗口的UI布局简化信息 uiautomator dump file 指定输出文件,默认文件是在/sdcard/window_dump.xml adb pull /sdcard/window_dump.xml

###分析 分析安装包中的AndroidManifest.xml 获取包名并且启动Activity名

com.tencent.wework.enterprise.attendance 打卡包

#adb命令获取当前界面Activity adb shell dumpsys activity activities adb shell dumpsys activity activities | grep 'cmp' ## 动态获取当前Activity 可以实时 查看当前正在运行的Activity; adb shell logcat | grep ActivityManager

## 然后输入 am start -n 应用的主包名/要打开的activity所在的包.要打开的activity的名称 , 如下(注:如果对应的Activity打不开则需要在清单文件的对应的Activity标签中添加 android:exported="true" 属性即可): adb shell am start com.tencent.wework/com.tencent.wework.enterprise.attendance.controller.AttendanceActivity2 com.tencent.wework/.launch.WwMainActivity

## 获取xml按钮的中心坐标 python uiautomator xml 解析 # -*- coding: utf-8 -*- import tempfile import os import re import time import xml.etree.ElementTree as ET

name ='发消息' tree = ET.ElementTree(file="./window_dump.xml") pattern = re.compile(r"\d+") treeIter = tree.iter(tag="node") for elem in treeIter: if elem.attrib['text'] == name: bounds = elem.attrib["bounds"] coord = pattern.findall(bounds) Xpoint = (int(coord[2]) - int(coord[0])) / 2.0 + int(coord[0]) Ypoint = (int(coord[3]) - int(coord[1])) / 2.0 + int(coord[1]) print (Xpoint) print (Ypoint) os.popen("adb shell input tap " + str(Xpoint) + " " + str(Ypoint))

#*采用框架库,使用这个第一版,第二版也比较蛋疼https://github.com/xiaocong/uiautomator #pip3 install uiautomator × 使用方法 https://www.cnblogs.com/wanghzh/p/9372021.html

#Appium自动化测试,这是封装好的,比自己撸简单。这种搭建环境比较蛋疼,重量级 Appium移动自动化测试 https://www.cnblogs.com/fnng/p/4540731.html pip install Appium-Python-Client

################################ #adb 命令大全 https://www.cnblogs.com/zhuminghui/p/10457316.html 1、查询已连接设备/模拟器

adb devices

2、指定设备获取屏幕分辨率

adb -s 设备号 shell wm size

3、给指定设备安装应用

adb -s 设备号 install test.apk

4、启动 adb server 命令

adb start-server

5、停止 adb server 命令

adb kill-server

6、查看adb版本

adb version

7、指定 adb server 的网络端口

adb -P <port> start-server

8、通过 IP 地址连接设备

adb connect <device-ip-address>

9、断开无线连接

adb disconnect <device-ip-address>

10、查看所有应用

adb shell pm list packages

11、查看系统应用

adb shell pm list packages -s

12、查看第三方应用

adb shell pm list packages -3

13、卸载应用(<packagename> 表示应用的包名,-k 参数可选,表示卸载应用但保留数据和缓存目录。)

adb uninstall [-k] <packagename>

14、清除应用数据与缓存

adb shell pm clear <packagename>

15、复制设备里的文件到电脑

adb pull <设备里的文件路径> [电脑上的目录]

16、复制电脑里的文件到设备

adb push <电脑上的文件路径> <设备里的目录>

17、电源键

adb shell input keyevent 26

18、菜单键

adb shell input keyevent 82

19、HOME 键

adb shell input keyevent 3

20、返回键

adb shell input keyevent 4

21、增加音量

adb shell input keyevent 24

22、降低音量

adb shell input keyevent 25

23、静音

adb shell input keyevent 164

24、播放/暂停

adb shell input keyevent 85

25、停止播放

adb shell input keyevent 86

26、播放下一首

adb shell input keyevent 87

27、播放上一首

adb shell input keyevent 88

28、恢复播放

adb shell input keyevent 126

29、暂停播放

adb shell input keyevent 127

30、滑动解锁(参数 300 1000 300 500 分别表示起始点x坐标 起始点y坐标 结束点x坐标 结束点y坐标。)

adb shell input swipe 300 1000 300 500

31、输入文本

adb shell input text hello

32、清空日志

adb logcat -c

33、查看设备型号

adb shell getprop ro.product.model

34、电池状况

adb shell dumpsys battery

35、屏幕分辨率

adb shell wm size

36、屏幕密度

adb shell wm density

37、显示屏参数

adb shell dumpsys window displays

38、查看Android 系统版本

adb shell getprop ro.build.version.release

39、查看IP 地址

adb shell ifconfig | grep Mask

40、Mac 地址

adb shell cat /sys/class/net/wlan0/address

41、CPU 信息

adb shell cat /proc/cpuinfo

42、内存信息

adb shell cat /proc/meminfo

43、使用 Monkey 进行压力测试(表示向 <packagename> 指定的应用程序发送 500 个伪随机事件。)

adb shell monkey -p <packagename> -v 500

44、查看进程

adb shell ps

45、查看实时资源占用情况

adb shell top

#无root 开启网络调试 使用usb连接手机,adb shell 进入终端执行 setprop service.adb.tcp.port 5555 设置好后,手动重启usb调试,在开发者模式,usb调试开关,关闭打开一次就好 退出adb shell exit 执行adb tcpip 5555 出现如下提示说明切换成功 restarting in TCP mode port:5555 然后输入 adb connect 192.168.1.102:5555 出现如下提示说明连接成功 connected to 192.168.1.102:5555 执行 adb devices 会出现两个设备,然后断开usb线路。 adb shell 就可以连接上了

×关闭wifi adb 断开和手机的链接 adb disconnect 切换到usb调试 adb usb ×连接指定设备 adb -s 设备号 shell *adb 重启 adb kill-server

```

AirtestIDE

  • AirtestIDE:跨平台的UI自动化测试编辑器,适用于游戏和App
  • 访问官网

注意,这个玩意儿是个神器,但是我感觉有点重了,毕竟人家可以自动化测试游戏滴~~~

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-05-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • # 笔记相关
  • AirtestIDE
相关产品与服务
实时音视频
实时音视频(Tencent RTC)基于腾讯21年来在网络与音视频技术上的深度积累,以多人音视频通话和低延时互动直播两大场景化方案,通过腾讯云服务向开发者开放,致力于帮助开发者快速搭建低成本、低延时、高品质的音视频互动解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档