python使用Android-adb调用钉钉实现自动打卡
- 前提
前提 python调用Android-adb调用钉钉自动打卡。前提:
1.Android机留在公司;
2. 需要一个运行python的主机,可以是公司电脑装个linux虚拟机,可以是有系统的开发板
【钉钉自动打卡】#话不多说上代码
sudo apt-get update
sudo apt-get install -y android-tools-adb android-tools-fastboot
import time
import threading
import os,subprocess
import base64
import random
PATH = lambda p: os.path.abspath(p)isScreenshoting = False
#打卡
def onWork():
# 开个线程截图
ts = threading.Thread(target=runLoopScreenshot, args=())
ts.setDaemon(True)
global isScreenshoting
isScreenshoting = True
ts.start()
os.system('adb shell input keyevent 26')
os.system('adb shell input keyevent 3')
os.system('adb shell am start -n com.alibaba.android.rimet/com.alibaba.android.rimet.biz.SplashActivity')
# 等15秒后关闭
time.sleep(15)
os.system('adb shell input keyevent 3')
os.system('adb shell input keyevent 6')
isScreenshoting = False
# 打卡完毕
tend = threading.Thread(target=enddk, args=())
tend.start()def enddk():
# 通知你想通知的地方
print("end")
time.sleep(10)def runLoopScreenshot():
global isScreenshoting
while isScreenshoting:
# os.popen("adb wait-for-device")
s = os.popen("adb shell screencap -p| base64").read()
print(s)
os.popen("adb shell screencap -p /data/local/tmp/tmp.png")
path = '/home/pi'
os.popen("adb pull /data/local/tmp/tmp.png " + PATH(path + "/s.png"))
# os.popen("adb shell rm /data/local/tmp/tmp.png")
# 图片转了base64 可以发到你想发的地方
with open(path + "/s.png", "rb") as f:
base64_data = https://www.it610.com/article/base64.b64encode(f.read())print('success')if __name__ == '__main__':
# 设置多几个打卡时间
dakaTime = ['08:49:40', '08:47:32', '08:53:25']
nextDakaTime = None
while True:
try:
# 看有没有设备连接
device = os.popen('adb devices -l').read()
out = device.split(' ')
print('{"action":"device","data":"%s,%s,%s"}' % (out[11], out[12], out[13]))
currentTime = time.strftime("%H:%M:%S", time.localtime())if nextDakaTime == None:
r = random.randint(0, len(dakaTime) - 1)
nextDakaTime = dakaTime[r]
print(currentTime,nextDakaTime)
if currentTime == nextDakaTime:
# 开个线程打卡
t = threading.Thread(target=onWork, args=())
t.setDaemon(True)
t.start()
except Exception as e:
print("something wrong:", e)
time.sleep(1)
推荐阅读
- Python|APP开发用什么框架最好(这5大框架,开发者必备神器)
- 人工智能+大数据|特征工程(特征预处理(无量纲化处理))
- 程序员|作为一只Python爬虫(如何破解滑动验证码)
- python批量自动整理文件
- Python爬虫|逆向系列 | AES逆向加密案例分析
- javascript|某数和某5秒-反混淆动态注入调试的一种方案
- python|Python+Celery实现基于Fastnetmon异常流量清洗
- 游戏|超级玛丽的 python 实现
- python|基于移动最小二乘(MLS)的图像扭曲刚性变形python实现