使用Python实现企业微信的自动打卡功能

yipeiwu_com6年前Python基础

上下班打卡是程序员最讨厌的东西,更讨厌的是设置了连上指定wifi打卡。

手机上有一些定时机器人之类的app,经过实际测试,全军覆没,没一个可以活着走到启动企业微信的这一步,所以还是靠自己吧。

下面就通过Python程序来实现自动打卡,原理很简单,用Python设置定时任务,然后通过adb操作手机,完成打卡。

1、准备工作

a、安装了Python,ADB驱动(安装方式及下载地址见之前文章)的电脑一台;常驻在公司的测试机一台;数据线一条。

b、将手机通过数据线连接电脑,打开开发者选项中的允许USB调试,然后命令行运行adb devices来测试下是否能显示设备,ok则准备工作完毕。

2、实现代码

#本手机安装了企业微信分身,可以打两个人的卡
# coding: utf-8
import os
import sys
import time
import schedule
import requests

def click():
 #打第一个卡
 os.system('adb shell input keyevent 82')#点亮屏幕
 time.sleep(1)
 os.system('adb shell input keyevent 3')#单击home键,回到主页
 time.sleep(1)
 os.system('adb shell input swipe 500 300 300 300')#左划屏幕
 time.sleep(1)
 os.system('adb shell input swipe 500 300 300 300')#左划屏幕
 time.sleep(2)
 os.system('adb shell input tap 920 800')#点击企业微信
 time.sleep(5)
 os.system('adb shell input tap 678 1820')
 time.sleep(5)
 os.system('adb shell input tap 410 330')
 time.sleep(10)
 os.system('adb shell input tap 540 1340')
 time.sleep(5)
 #打第二个卡
 os.system('adb shell input keyevent 3')
 time.sleep(1)
 os.system('adb shell input swipe 500 300 300 300')
 time.sleep(1)
 os.system('adb shell input swipe 500 300 300 300')
 time.sleep(2)
 os.system('adb shell input tap 660 1100')
 time.sleep(5)
 os.system('adb shell input tap 678 1820')
 time.sleep(5)
 os.system('adb shell input tap 410 330')
 time.sleep(10)
 os.system('adb shell input tap 540 1340')
 time.sleep(5)
 #推送消息给微信,此处可以删除,仅为通知
 url = 'http://wxmsg.dingliqc.com/send?msg=打卡成功&userIds=自己微信的uid'
 requests.get(url)
 sys.exit()
def main():
 '''
 主函数
 '''
 schedule.every().day.at('18:03').do(click)
 while True:
  schedule.run_pending()
  time.sleep(3)
if __name__ == '__main__':
 main()

关于代码中涉及到的坐标点,可以通过手机页面截图,放到电脑里编辑图片来查看触摸点的坐标值,跟机型和分辨率有关,需要针对自己的手机调试,sleep的时间根据手机性能,网络环境可以做优化,然后运行代码就行了。想后台运行的话

start /b python startwork.py

当然,最重要的一点,电脑要保持24H开机,程序员不担心这个,因为真正的程序员从不关机。

总结

以上所述是小编给大家介绍的使用Python实现企业微信的自动打卡功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于Python设计】网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

相关文章

PyTorch 随机数生成占用 CPU 过高的解决方法

PyTorch 随机数生成占用 CPU 过高的问题 今天在使用 pytorch 的过程中,发现 CPU 占用率过高。经过检查,发现是因为先在 CPU 中生成了随机数,然后再调用.to(d...

python中的格式化输出用法总结

本文实例总结了python中的格式化输出用法。分享给大家供大家参考,具体如下: Python一共有两种格式化输出语法。 一种是类似于C语言printf的方式,称为 Formatting...

Python的Django框架中模板碎片缓存简介

你同样可以使用cache标签来缓存模板片段。 在模板的顶端附近加入{% load cache %}以通知模板存取缓存标签。 模板标签{% cache %}在给定的时间内缓存了块的内容。...

对Python中plt的画图函数详解

1、plt.legend plt.legend(loc=0)#显示图例的位置,自适应方式 说明: 'best' : 0, (only implemented for ax...

详解python运行三种方式

方式一 交互式编程 交互式编程不需要创建脚本文件,是通过 Python 解释器的交互模式进来编写代码。 linux上你只需要在命令行中输入 Python 命令即可启动交互式编程,提示窗口...