钉钉-自动打卡

环境准备

Mac
1、uiautomator2

(1)先安装好uiautomator2环境:https://github.com/openatx/uiautomator2

(2)创建dingding.py脚本,用来是实现打开

import os
import uiautomator2 as u2
from time import sleep


def unlockScreen(d):
    '''

    :param d:解锁屏幕
    :return:
    '''
    d.press("home")
    d.swipe(0.508, 0.745, 0.533, 0.444)
    #d.unlock()  因为本人为小米5S Plus,该解锁方式不生效

    sleep(3)


def sessionCheck(d, sess):
    '''
    :param d:
    :param sess:判断短信是否活跃
    :param num: 给第一次加载配置文件30s
    :return:
    '''
    run_stat = sess.running()

    if run_stat == False:
        print(run_stat)
        d.session("com.alibaba.android.rimet")

    # 总是在桌面操作锁屏
    d.press("home")

    sleep(3)


def dingdingtalkRun(d):
    '''
    :param d:
    :return:
    '''
    d.app_start("com.alibaba.android.rimet")

    sleep(5)

    # 工作://*[@resource-id="com.alibaba.android.rimet:id/home_bottom_tab_button_work"]
    d.xpath('//*[@resource-id="com.alibaba.android.rimet:id/home_bottom_tab_button_work"]').click()
    sleep(5)

    # d.click(0.162, 0.572)
    # 考勤打卡://android.webkit.WebView/android.view.View[1]/android.view.View[3]/android.view.View[3]/android.view.View[1]
    d.click(0.162, 0.572)
    sleep(5)

    # 允许定位:d.xpath('//*[@resource-id="android:id/button1"]')
    # d.click(0.653, 0.945)
    if d.xpath('//*[@resource-id="android:id/button1"]').exists:
        d.xpath('//*[@resource-id="android:id/button1"]').click()

    if d.xpath('//*[@content-desc="上班打卡"]').exists:
        d.xpath('//*[@content-desc="上班打卡"]').click()
        print('打卡成功了')

    d.press("home")


def run(d):
    '''
    :param d:uiautomator2是否starting
    :param num:
    :return:6
    '''
    print('start')

    # 解锁
    unlockScreen(d)
    d.healthcheck()

    dingdingtalkRun(d)

    # 锁屏
    d.press("power")
    print('power down')


if __name__ == '__main__':
    d = u2.connect()
    run(d)
2、crontab

(1)编辑添加定时任务
终端创建一个定时任务:crontab -e
添加要执行的任务:
*/3 16 * * *脚本存放位置/run.sh

(2)调用run.py的shell脚本

# 进入run.py程序所在目录
cd 脚本存放位置 &&
# 执行python脚本(注意前面要指定python运行环境/usr/bin/python,根据自己的情况改变)
~/.pyenv/versions/3.6.4/bin/python dingding.py
Android手机
1、关闭锁屏密码
2、USB调试
3、登录钉钉

你可能感兴趣的:(钉钉-自动打卡)