ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

[python][企业微信]企业微信自动打卡Python脚本,价值一万元的自动打卡脚本

2020-05-09 12:03:22  阅读:273  来源: 互联网

标签:脚本 微信 datetime sleep time print 打卡 text


# -*- coding: utf-8 -*-
import datetime
import os
import random
import time
import schedule
# 引入uiautomator库
from pip._vendor import requests
from uiautomator import device as d

# 法定节假日准确日期,不进行打卡
holiday = ['2020-06-25',
           '2020-06-26',
           '2020-06-27',
           '2020-10-01',
           '2020-10-02',
           '2020-10-03',
           '2020-10-04',
           '2020-10-05',
           '2020-10-06',
           '2020-10-07',
           '2020-10-08',
           ]
# 调整工作日准确日期,进行打卡
ajustWorking = ['2020-05-09', '2020-06-28', '2020-09-27', '2020-10-10']
# 调休日期,不进行打卡
compensatoryLeave = ['2020-05-16']


def init():
    # 初始化信息
    print(d.info)
    # 点亮屏幕
    # d.screen.on()
    os.popen("adb shell input keyevent 224")
    time.sleep(1)
    # 滑动屏幕
    os.popen("adb shell input swipe 300 2000 300 500")
    time.sleep(1)
    # 输入密码
    os.popen("adb shell input text 密码")  # 你的手机密码
    time.sleep(1)


def openwework():
    """
    企业微信打卡
    clock in out 上班 下班
    :return:
    """
    init()
    msg = 0
    # 先结束再开启
    os.popen("adb shell am force-stop com.tencent.wework")
    time.sleep(1)
    os.popen("adb shell am start com.tencent.wework/com.tencent.wework.launch.LaunchSplashActivity")
    time.sleep(5)
    print("启动企业微信成功")
    d(text=u"工作台").click()
    time.sleep(1)
    d(text=u"打卡").click()
    time.sleep(3)
    print("打开打卡界面成功")
    print("当前小时:", datetime.datetime.now().hour)

    if datetime.datetime.now().hour < 11:
        # 早晨卡
        if d(text=u"你已在打卡范围内").info['text'] == "你已在打卡范围内":
            print("现在是上午")
            d(text=u"上班打卡").click()
            time.sleep(2)
            if d(text=u"上班·正常").info['text'] == "上班·正常":
                in_time = d(className="android.widget.TextView", resourceId="com.tencent.wework:id/mp").info['text']
                print("打卡时间:", in_time)
                msg = "上班打卡成功: 时间:" + in_time + " 日志时间:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            else:
                msg = "打卡失败:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    else:
        # 下班卡
        if d(text=u"你已在打卡范围内").info['text'] == "你已在打卡范围内":
            print("现在是下午")
            d(text=u"下班打卡").click()
            time.sleep(2)
            if d(text=u"下班·正常").info['text'] == "下班·正常":
                in_time = d(className="android.widget.TextView", resourceId="com.tencent.wework:id/mp").info['text']
                print("打卡时间:", in_time)
                msg = "下班打卡成功: 时间:" + in_time + " 日志时间:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            else:
                msg = "打卡失败:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # 返回桌面
    time.sleep(1)
    os.popen("adb shell input keyevent 3")
    time.sleep(1)
    os.popen("adb shell am force-stop com.tencent.wework")
    time.sleep(1)
    return msg


# 启动微信
def wexin():
    # 按home键
    os.popen("adb shell input keyevent 3")
    time.sleep(1)
    os.popen("adb shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI")
    time.sleep(3)
    print("启动微信成功")
    d(text=u"通讯录").click()
    time.sleep(1)
    d(text=u"你自己的微信名字").click()  # 你自己的微信名字  
    time.sleep(2)
    d(text=u"音视频通话").click()
    time.sleep(1)
    d(text=u"语音通话").click()
    # 振铃五秒钟
    time.sleep(5)
    # d(text=u"取消").click()
    os.popen("adb shell input tap 540 1850")
    time.sleep(3)
    # 按返回键
    os.popen("adb shell input keyevent 4")
    time.sleep(2)
    os.popen("adb shell input keyevent 4")
    time.sleep(1)
    # 按home键
    os.popen("adb shell input keyevent 3")
    time.sleep(1)
    os.popen("adb shell am force-stop com.tencent.mm")
    print("结束微信成功")
    time.sleep(1)
    # 锁屏
    os.popen("adb shell input keyevent 26")


def pushmsg(msg):
    """
    推送消息给微信
    :return:
    """
    try:
        url = 'http://wxpusher.zjiecode.com/api/send/message/?appToken=你自己的token&content=' + msg + '&uid=你自己的uid'
        requests.get(url)
    except Exception:
        print("推送消息异常")


def fuckCard():
    # 设置增加的随机分钟数
    clocknum = 3
    # 获取当前时间,2020-05-05 07:45
    nowtime = datetime.datetime.now()
    print("当前时间:", nowtime)
    # 加上随机数(0-3分钟),2020-05-05 07:46
    doworktime = (nowtime + datetime.timedelta(minutes=random.randint(0, clocknum))).strftime("%Y-%m-%d %H:%M")
    print("执行任务时间:", doworktime)
    a = 0
    # 如果当前时间小于执行时间,执行while循环
    while time.strftime("%Y-%m-%d %H:%M", time.localtime()) < doworktime:
        print("秒数:", a)
        a += 1
        time.sleep(1)
    # 到时间执行任务
    # 如果当前时间大于执行时间,执行任务
    if time.strftime("%Y-%m-%d %H:%M", time.localtime()) >= doworktime:
        print("到时间执行任务")
        msg = openwework()
        pushmsg(msg)
        wexin()
        return


def fuckRest():
    """
    # 搞定随机时间
    :return:
    """
    if time.strftime("%Y-%m-%d", time.localtime()) in holiday:
        print("今天是法定假日")
        return True
    if time.strftime("%Y-%m-%d", time.localtime()) in compensatoryLeave:
        print("今天是调休日期,不进行打卡~~")
        return True
    if time.strftime("%Y-%m-%d", time.localtime()) in ajustWorking:
        print("今天是调整工作日,需要进行打卡")
        # 周六启动计划任务问题,需要进行时间判断修复 schedule.every().saturday.at('12:09').do(fuckRest)
        # 也就是是避免 12点问题
        if datetime.datetime.now().hour != 12:
            print("调整工作日,早8八点,晚6点,正常打卡")
            fuckCard()
        return True

    # 判断是否为周一到周六上午
    # 1.判断当前日期是否为周日
    if datetime.datetime.now().weekday() != 6:
        if datetime.datetime.now().weekday() != 5:
            print("周一至周五")
            fuckCard()
        else:
            print("今天是周六")
            if (datetime.datetime.now().hour >= 8) and (datetime.datetime.now().hour < 13):
                print("周六半天打卡")
                fuckCard()



# 企业微信自动打卡
if __name__ == "__main__":
    '''
    主函数
    linux 后台运行
    nohup python3 -u main.py > main.log 2>&1 &
    Windows 
    start /b python3 main.py
    # 我司工作日:周一至周五,早8晚6。周六早8点半,中午12点。
    '''
    # 每天执行打卡
    # 第一个卡
    schedule.every().day.at('07:45').do(fuckRest)
    # # 周六执行此任务
    # 正常工作日周六早晨卡
    schedule.every().saturday.at('08:13').do(fuckRest)
    # 正常工作日周六中午卡
    schedule.every().saturday.at('12:09').do(fuckRest)
    # # 第二个卡
    schedule.every().day.at('18:11').do(fuckRest)
    while True:
        schedule.run_pending()
        time.sleep(3)

[python][企业微信]企业微信自动打卡Python脚本 价值一万元的自动打卡脚本

这个Python脚本还是有bug的,暂时不在维护和修复了,如果按照既定规划的执行不会出现错误。

当然,断网,断电,手机异常升级,重启等等错误,仍然需要人工进行搞定。

不过嘛,当没有收到提醒通知的时候,人工看看吧,也就早晨和下班那么一哆嗦,这要保证这一哆嗦不错误就好了。

反正我暂时没有遇见错误呢,遇见的时候再说吧,欢迎大家把错误信息发给我。

 

 

价值一万元的自动打卡脚本,表问我为毛价值一万元,你懂得,哇哈哈哈。

 

标签:脚本,微信,datetime,sleep,time,print,打卡,text
来源: https://www.cnblogs.com/landv/p/12856446.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有