# -*- 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 = 'https://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)# -*- coding: utf-8 -*-
import datetim