1 Star 0 Fork 0

londuy/dingding-adb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 3.96 KB
一键复制 编辑 原始数据 按行查看 历史
londuy 提交于 2024-08-08 23:59 +08:00 . init
#!/usr/bin/python3
import os
import random
import subprocess
import time
import cv2
import datetime
import schedule
import numpy as np
def get_latest_image(data_dir):
files = os.listdir(data_dir)
if not files:
return None
files.sort(key=lambda x: os.path.getmtime(os.path.join(data_dir, x)), reverse=True)
return os.path.join(data_dir, files[0])
def compare_images(img1_path, img2_path, threshold=0.9):
image1 = cv2.imread(img1_path)
image2 = cv2.imread(img2_path)
if image1 is None and image2 is None:
return False
result = cv2.matchTemplate(image1, image2, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val >= threshold:
print("相似度"+str(max_val))
return True
else:
print("相似度"+str(max_val))
return False
def main(img1_path, img2_path, data_dir, command, max_attempts=10):
attempts = 0
while attempts < max_attempts:
latest_image = get_latest_image(data_dir)
if not latest_image:
print("目录中没有照片。")
subprocess.run(command, shell=True)
break
subprocess.run(command, shell=True)
latest_image_after_command = get_latest_image(data_dir)
if latest_image == latest_image_after_command:
print("执行后照片没有变化,重新执行指令。")
else:
if compare_images(img1_path, latest_image_after_command) or compare_images(img2_path,
latest_image_after_command):
print("照片内容一致,任务完成。")
break
else:
print("照片内容不一致,重新执行指令。")
time.sleep(3)
attempts += 1
if attempts == max_attempts:
print("达到最大尝试次数,任务失败。")
def start():
current_script_path = os.path.abspath(__file__)
path_img1 = os.path.join(os.path.dirname(current_script_path), "data", "image1.png")
path_img2 = os.path.join(os.path.dirname(current_script_path), "data", "image2.png")
data_dir = "/volume/scripts_data/duty"
command = "/volume/scripts/duty.sh"
main(path_img1, path_img2, data_dir, command)
def run1():
current_time = datetime.datetime.now()
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("开始时间:", formatted_time)
random_delay = random.randint(1, 1800)
print(f"等待时间:{random_delay}")
time.sleep(random_delay)
current_time = datetime.datetime.now()
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("结束时间:", formatted_time)
start()
def run2():
# 获取当前日期和时间
current_time = datetime.datetime.now()
# 将时间格式化为字符串并打印
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("开始时间:", formatted_time)
random_delay = random.randint(1, 20)
print(f"等待时间:{random_delay}")
time.sleep(random_delay)
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
print("结束时间:", formatted_time)
start()
if __name__ == "__main__":
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin"
schedule.every().sunday.at("07:00").do(run1)
schedule.every().monday.at("07:00").do(run1)
schedule.every().tuesday.at("07:00").do(run1)
schedule.every().wednesday.at("07:00").do(run1)
schedule.every().thursday.at("07:00").do(run1)
schedule.every().friday.at("07:00").do(run1)
schedule.every().sunday.at("18:00").do(run2)
schedule.every().monday.at("18:00").do(run2)
schedule.every().tuesday.at("18:00").do(run2)
schedule.every().wednesday.at("18:00").do(run2)
schedule.every().thursday.at("18:00").do(run2)
schedule.every().friday.at("18:00").do(run2)
schedule.run_pending()
while True:
time.sleep(0.1)
schedule.run_pending()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/koduy/dingding-adb.git
git@gitee.com:koduy/dingding-adb.git
koduy
dingding-adb
dingding-adb
master

搜索帮助