# -*- 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的,暫時不在維護和修復了,如果按照既定規划的執行不會出現錯誤。
當然,斷網,斷電,手機異常升級,重啟等等錯誤,仍然需要人工進行搞定。
不過嘛,當沒有收到提醒通知的時候,人工看看吧,也就早晨和下班那么一哆嗦,這要保證這一哆嗦不錯誤就好了。
反正我暫時沒有遇見錯誤呢,遇見的時候再說吧,歡迎大家把錯誤信息發給我。
價值一萬元的自動打卡腳本,表問我為毛價值一萬元,你懂得,哇哈哈哈。
# 筆記相關
``` text
# Android sdk tools
/home/landv/Android/Sdk/tools/bin/uiautomatorviewer
# 啟動微信
adb shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI
# 殺死微信進程
adb shell am force-stop com.tencent.mm
# 啟動企業微信
adb shell am start com.tencent.wework/com.tencent.wework.launch.LaunchSplashActivity
# 殺死企業微信進程
adb shell am force-stop com.tencent.wework
# 加班休息扣除方式test
adb shell am start com.tencent.wework/com.tencent.wework.enterprise.attendance.rule.TestExportActivity
# 人臉信息
adb shell am start com.tencent.wework/com.tencent.wework.enterprise.attendance.controller.AttendanceFaceDetailActivity
#adb shell uiautomator 命令
uiautomator dump dump出當前窗口的UI布局信息
uiautomator dump --compressed dump出當前窗口的UI布局簡化信息
uiautomator dump file 指定輸出文件,默認文件是在/sdcard/window_dump.xml
adb pull /sdcard/window_dump.xml
###分析
分析安裝包中的AndroidManifest.xml
獲取包名並且啟動Activity名
com.tencent.wework.enterprise.attendance 打卡包
#adb命令獲取當前界面Activity
adb shell dumpsys activity activities
adb shell dumpsys activity activities | grep 'cmp'
## 動態獲取當前Activity 可以實時 查看當前正在運行的Activity;
adb shell logcat | grep ActivityManager
##
然后輸入 am start -n 應用的主包名/要打開的activity所在的包.要打開的activity的名稱 , 如下(注:如果對應的Activity打不開則需要在清單文件的對應的Activity標簽中添加 android:exported="true" 屬性即可):
adb shell am start com.tencent.wework/com.tencent.wework.enterprise.attendance.controller.AttendanceActivity2
com.tencent.wework/.launch.WwMainActivity
## 獲取xml按鈕的中心坐標 python uiautomator xml 解析
# -*- coding: utf-8 -*-
import tempfile
import os
import re
import time
import xml.etree.ElementTree as ET
name ='發消息'
tree = ET.ElementTree(file="./window_dump.xml")
pattern = re.compile(r"\d+")
treeIter = tree.iter(tag="node")
for elem in treeIter:
if elem.attrib['text'] == name:
bounds = elem.attrib["bounds"]
coord = pattern.findall(bounds)
Xpoint = (int(coord[2]) - int(coord[0])) / 2.0 + int(coord[0])
Ypoint = (int(coord[3]) - int(coord[1])) / 2.0 + int(coord[1])
print (Xpoint)
print (Ypoint)
os.popen("adb shell input tap " + str(Xpoint) + " " + str(Ypoint))
#*采用框架庫,使用這個第一版,第二版也比較蛋疼https://github.com/xiaocong/uiautomator
#pip3 install uiautomator
× 使用方法
https://www.cnblogs.com/wanghzh/p/9372021.html
#Appium自動化測試,這是封裝好的,比自己擼簡單。這種搭建環境比較蛋疼,重量級
Appium移動自動化測試
https://www.cnblogs.com/fnng/p/4540731.html
pip install Appium-Python-Client
################################
#adb 命令大全
https://www.cnblogs.com/zhuminghui/p/10457316.html
1、查詢已連接設備/模擬器
adb devices
2、指定設備獲取屏幕分辨率
adb -s 設備號 shell wm size
3、給指定設備安裝應用
adb -s 設備號 install test.apk
4、啟動 adb server 命令
adb start-server
5、停止 adb server 命令
adb kill-server
6、查看adb版本
adb version
7、指定 adb server 的網絡端口
adb -P <port> start-server
8、通過 IP 地址連接設備
adb connect <device-ip-address>
9、斷開無線連接
adb disconnect <device-ip-address>
10、查看所有應用
adb shell pm list packages
11、查看系統應用
adb shell pm list packages -s
12、查看第三方應用
adb shell pm list packages -3
13、卸載應用(<packagename> 表示應用的包名,-k 參數可選,表示卸載應用但保留數據和緩存目錄。)
adb uninstall [-k] <packagename>
14、清除應用數據與緩存
adb shell pm clear <packagename>
15、復制設備里的文件到電腦
adb pull <設備里的文件路徑> [電腦上的目錄]
16、復制電腦里的文件到設備
adb push <電腦上的文件路徑> <設備里的目錄>
17、電源鍵
adb shell input keyevent 26
18、菜單鍵
adb shell input keyevent 82
19、HOME 鍵
adb shell input keyevent 3
20、返回鍵
adb shell input keyevent 4
21、增加音量
adb shell input keyevent 24
22、降低音量
adb shell input keyevent 25
23、靜音
adb shell input keyevent 164
24、播放/暫停
adb shell input keyevent 85
25、停止播放
adb shell input keyevent 86
26、播放下一首
adb shell input keyevent 87
27、播放上一首
adb shell input keyevent 88
28、恢復播放
adb shell input keyevent 126
29、暫停播放
adb shell input keyevent 127
30、滑動解鎖(參數 300 1000 300 500 分別表示起始點x坐標 起始點y坐標 結束點x坐標 結束點y坐標。)
adb shell input swipe 300 1000 300 500
31、輸入文本
adb shell input text hello
32、清空日志
adb logcat -c
33、查看設備型號
adb shell getprop ro.product.model
34、電池狀況
adb shell dumpsys battery
35、屏幕分辨率
adb shell wm size
36、屏幕密度
adb shell wm density
37、顯示屏參數
adb shell dumpsys window displays
38、查看Android 系統版本
adb shell getprop ro.build.version.release
39、查看IP 地址
adb shell ifconfig | grep Mask
40、Mac 地址
adb shell cat /sys/class/net/wlan0/address
41、CPU 信息
adb shell cat /proc/cpuinfo
42、內存信息
adb shell cat /proc/meminfo
43、使用 Monkey 進行壓力測試(表示向 <packagename> 指定的應用程序發送 500 個偽隨機事件。)
adb shell monkey -p <packagename> -v 500
44、查看進程
adb shell ps
45、查看實時資源占用情況
adb shell top
#無root 開啟網絡調試
使用usb連接手機,adb shell 進入終端執行
setprop service.adb.tcp.port 5555
設置好后,手動重啟usb調試,在開發者模式,usb調試開關,關閉打開一次就好
退出adb shell
exit
執行adb tcpip 5555
出現如下提示說明切換成功
restarting in TCP mode port:5555
然后輸入
adb connect 192.168.1.102:5555
出現如下提示說明連接成功
connected to 192.168.1.102:5555
執行 adb devices
會出現兩個設備,然后斷開usb線路。
adb shell 就可以連接上了
×關閉wifi adb
斷開和手機的鏈接
adb disconnect
切換到usb調試
adb usb
×連接指定設備
adb -s 設備號 shell
*adb 重啟
adb kill-server
```
AirtestIDE
- AirtestIDE:跨平台的UI自動化測試編輯器,適用於游戲和App
- 訪問官網
注意,這個玩意兒是個神器,但是我感覺有點重了,畢竟人家可以自動化測試游戲滴~~~