钉钉自动打卡


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)

    推荐阅读