diff --git a/AI/Ylt/CommonUtil.py b/AI/Ylt/CommonUtil.py new file mode 100644 index 00000000..f34f4f95 --- /dev/null +++ b/AI/Ylt/CommonUtil.py @@ -0,0 +1,23 @@ +import time +from Config import * +# 等待 +def wait(seconds=0.5): + time.sleep(seconds) + + + +# 登录 +def login(page): + # 打开登录页面 + page.goto("https://ww1.colorlightcloud.com/login", wait_until="domcontentloaded") # 等待 DOM 加载完成 + # 输入用户名 + username_input = page.locator("#mat-input-0") # 通过 id 定位用户名输入框 + username_input.fill(USERNAME) + # 输入密码 + password_input = page.locator("input[type='password']") # 根据实际元素定位密码输入框 + password_input.fill(PASSWORD) + # 点击登录按钮 + login_button = page.locator("button.color-login-btn") # 通过 class 定位登录按钮 + login_button.click() + # 等待登录成功 + page.wait_for_url("https://ww1.colorlightcloud.com/home", timeout=60000) # 等待跳转到 home 页面 diff --git a/AI/Ylt/Config.py b/AI/Ylt/Config.py new file mode 100644 index 00000000..85bef09c --- /dev/null +++ b/AI/Ylt/Config.py @@ -0,0 +1,13 @@ +# 隐藏浏览器 +# HEADLESS = True +HEADLESS = False +# 素材的固定文件夹名称 +MATERIAL_FOLDER_NAME = '播报充电情况' +# 用户名 +USERNAME = 'Ylt5786' +# 密码 +PASSWORD = 'DJCtjy064' +# 前缀 +PREFIX_NAME = 'Test' +# 视频文件 +VIDEO_PATH = r"d:\1.mp4" \ No newline at end of file diff --git a/AI/Ylt/PaiCheng.py b/AI/Ylt/PaiCheng.py new file mode 100644 index 00000000..b745aa88 --- /dev/null +++ b/AI/Ylt/PaiCheng.py @@ -0,0 +1,172 @@ +from playwright.sync_api import Playwright, sync_playwright +from Ylt.CommonUtil import * + + +# 切换到节目 +def changeJieMu(page): + # 点击“节目” + print("点击节目...") + program_library = page.get_by_text("节目").nth(0) # 通过 text 定位媒体库 + program_library.click() + # 等待 + wait() + + +# 排程 +def paiCheng(page, keyword, stHour, stMin, stSec, endHour, endMin, endSec): + pc_library = page.get_by_text("排程").nth(0) + pc_library.click() + + # 等待 + wait() + # 定位目标 元素 + today_span = page.locator("span.mat-button-toggle-label-content", has_text="日") + today_span.click() + # 等待 + wait() + + # 定位目标 元素 + add_icon = page.locator("mat-icon", has_text="add").nth(1) + + # 点击 元素 + if add_icon.count() > 0: # 确保元素存在 + add_icon.click() + # 定位目标 元素 + broadcast_span = page.locator("span.mat-radio-label-content", has_text="插播") + + # 点击 元素 + if broadcast_span.count() > 0: # 确保元素存在 + broadcast_span.click() + # 等待 + wait() + + # 点击 + 号 + add_icon = page.locator("mat-icon", has_text="add").nth(2) + add_icon.click() + # 等待 + wait() + + # 等待目标对话框出现 + dialog = page.get_by_role('dialog', name='选择节目') # 通过对话框标题定位 + dialog.wait_for(state="visible") + + # 在对话框内操作 + # 定位所有 元素 + spans = dialog.locator("span") + + # 获取所有 元素的文本内容 + text_list = spans.evaluate_all("elements => elements.map(span => span.textContent.trim())") + + # 找到第一个以 keyword 开头的 元素 + for index, text in enumerate(text_list): + if text.startswith(keyword): + print(f"Found first span with text: {text}") + # 获取元素的句柄并强制点击 + span_handle = spans.nth(index).element_handle() + span_handle.evaluate("element => element.click()") + break # 找到第一个后退出循环 + + for index, text in enumerate(text_list): + if text.startswith("确认"): + print(f"Found first span with text: {text}") + span_handle = spans.nth(index).element_handle() + span_handle.evaluate("element => element.click()") + break + wait() + + # 定位目标滑动开关的“滑块”部分 + toggle_thumb = page.locator("div.mat-slide-toggle-thumb").nth(0) + # 点击“滑块”部分 + toggle_thumb.click() + wait() + + # 输入开始时间 + input_element = page.locator("input#mat-input-3") # 通过 id 定位 + input_element.click() + wait() + + # 定位目标 元素 + hour_input = page.locator("input.owl-dt-timer-input").nth(0) # 第一个输入框(小时) + minute_input = page.locator("input.owl-dt-timer-input").nth(1) # 第二个输入框(分钟) + second_input = page.locator("input.owl-dt-timer-input").nth(2) # 第三个输入框(秒) + # 输入时间 + hour_input.fill(stHour) # 输入小时 + wait() + minute_input.fill(stMin) # 输入分钟 + wait() + second_input.fill(stSec) # 输入秒 + wait() + # 设定 + set_button = page.locator("button.owl-dt-control-button", has_text="Set") + set_button.click() + wait() + + # ========================================== 输入结束时间========================================== + time_input = page.locator("input#mat-input-4") # 通过 id 定位 + time_input.click() + wait() + + hour_input = page.locator("input.owl-dt-timer-input").nth(0) # 第一个输入框(小时) + minute_input = page.locator("input.owl-dt-timer-input").nth(1) # 第二个输入框(分钟) + second_input = page.locator("input.owl-dt-timer-input").nth(2) # 第三个输入框(秒) + + # 输入时间 + hour_input.fill(endHour) # 输入小时 + wait() + minute_input.fill(endMin) # 输入分钟 + wait() + second_input.fill(endSec) # 输入秒 + wait() + + # 定位