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

yipeiwu_com5年前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设计】网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

相关文章

python使用wxpy实现微信消息防撤回脚本

本文实例为大家分享了python实现微信消息防撤回的具体代码,供大家参考,具体内容如下 使用了sqlite3保存数据,当有人撤回消息时取出数据发送到文件传输助手。 文件的话会先保存到本地...

Python学习笔记整理3之输入输出、python eval函数

1. python中的变量: python中的变量声明不需要像C++、Java那样指定变量数据类型(int、float等),因为python会自动地根据赋给变量的值确定其类型。如 rad...

基于pandas数据样本行列选取的方法

注:以下代码是基于python3.5.0编写的 import pandas food_info = pandas.read_csv("food_info.csv") # ------...

使用python将mysql数据库的数据转换为json数据的方法

使用python将mysql数据库的数据转换为json数据的方法

由于产品运营部需要采用第三方个推平台,来推送消息。如果手动一个个键入字段和字段值,容易出错,且非常繁琐,需要将mysql的数据转换为json数据,直接复制即可。 本文将涉及到如何使用Py...

Django 使用logging打印日志的实例

Django使用python自带的logging 作为日志打印工具。简单介绍下logging。 logging 是线程安全的,其主要由4部分组成: Logger 用户使用的直接接口,将...