|
|
本帖最后由 hzy306016819 于 2024-4-8 22:30 编辑
群晖iptv系统,外部列表好像设置自动更新不会更新。这几天摸索使用py定时更新:使用群晖定时Py启动docker项目启动selenium-hub,使用selenium/node-chrome自动登陆群晖iptv系统。自动点击源更新。最后关闭selenium项目。
群晖需要安装python、pip。然后pip安装selenium。群晖定时启动py需要root权限(启动docker项目时需要)。

Docker Compose 保存文件 compose.yaml 在docker项目启动
version: "3"
services:
chrome:
image: selenium/node-chrome:latest
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_GRID_URL=http://0.0.0.0:4444
ports:
- "6901:5900"
- "1013:7900"
selenium-hub:
image: selenium/hub:latest
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
py文件:启动docker、调用iptv.py、停止docker服务。下面文件保存为py文件,定时启动
import subprocess
import time
import requests
import os
# Docker Compose 文件路径
compose_file_path = '/volume1/docker/selenium-hub/compose.yaml'
# 启动 Docker Compose 服务
def start_compose_services(compose_file_path):
command = ['docker-compose', '-f', compose_file_path, 'up', '-d']
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode == 0:
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print('{} selenium-hub 服务启动成功!'.format(now))
with open('logo.txt', 'a') as f: # 在 logo.txt 中追加内容
f.write('\n{} selenium-hub 服务启动成功!\n'.format(now)) # 换行
else:
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print('{} selenium-hub 服务启动失败:', stderr.decode())
with open('logo.txt', 'a') as f: # 在 logo.txt 中追加内容
f.write('\n{} selenium-hub 服务启动失败\n'.format(stderr.decode(), now)) # 换行
# 停止 Docker Compose 服务
def stop_compose_services(compose_file_path):
command = ['docker-compose', '-f', compose_file_path, 'down']
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
# now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
if process.returncode == 0:
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print('{} selenium-hub 服务停止成功!'.format(now))
with open('logo.txt', 'a') as f: # 在 logo.txt 中追加内容
f.write('{} selenium-hub 服务停止成功!\n'.format(now)) # 换行
else:
print('{} selenium-hub 服务停止失败:', stderr.decode())
with open('logo.txt', 'a') as f: # 在 logo.txt 中追加内容
f.write('{} selenium-hub 服务停止失败\n'.format(stderr.decode(), now)) # 换行
# 调用函数
start_compose_services(compose_file_path) # 这个是启动docker-selenium-hub服务
time.sleep(30)
print("正在执行群晖 iptv 直播源更新,请稍等。。。。。。")
result = subprocess.run(['python', '/volume1/docker/iptv/iptv.py'], capture_output=True, text=True) # 运行 iptv.py 脚本-填写自己iptv.py路径
output = result.stdout
print("gsw.py 的输出:")
print(output)
if result.returncode != 0:
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print("iptv.py 运行出错,忽略并继续...")
with open('logo.txt', 'a') as f: # 在 logo.txt 中追加内容
f.write('{} iptv.py 运行出错!\n'.format(now)) # 写入错误信息和时间
stop_compose_services(compose_file_path) # 停止docker-selenium-hub服务
iptv.py文件
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options as ChromeOption
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time
import subprocess
# ==========================================m_ipv6===================================================
driver = webdriver.Remote(
command_executor="http://群晖IP:444/wd/hub", # 这个填写自己群晖IP,
options=ChromeOption(),
)
driver.get('http://群晖IP:20230/iptv/') # 这个填写自己群晖IP
driver.set_window_size(1280, 683)
driver.find_element(By.ID, "username").send_keys("admin")
driver.find_element(By.ID, "password").send_keys("123456")
driver.find_element(By.ID, "login_key_enter").click()
time.sleep(1)
driver.find_element(By.LINK_TEXT, "频道列表").click()
# #time.sleep(1)
driver.find_element(By.LINK_TEXT, "默认频道").click()
# time.sleep(1)
# driver.find_element(By.NAME, "thirdlist").click()
# #time.sleep(1)
dropdown = driver.find_element(By.NAME, "thirdlist")
# time.sleep(1)
dropdown.find_element(By.XPATH, "//option[. = 'm_ipv6']").click() # 这个是外部列表的名称 m_ipv6
# time.sleep(1)
# driver.find_element(By.CSS_SELECTOR, "option:nth-child(2)").click()
# #time.sleep(1)
driver.find_element(By.ID, "updatelist").click()
try:
WebDriverWait(driver, timeout=10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".jconfirm-buttons >.btn")))
driver.find_element(By.CSS_SELECTOR, ".jconfirm-buttons >.btn").click()
print("m_ipv6更新完成")
result = "m_ipv6更新完成"
except TimeoutException:
print("m_ipv6更新失败")
result = "m_ipv6更新失败"
# 不论是否发生异常,都会执行的代码finally:
finally:
driver.quit()
# 获取当前时间
current_time = time.strftime("%Y-%m-%d %H:%M:%S")
# 打开文件用于写入,如果文件不存在则创建它
with open('logo.txt', 'a', encoding='utf-8') as file:
file.write(f"{current_time} {result}\n")
file.flush() # 刷新缓冲区
print(f"{current_time} {result}")
exit()
第一次发帖,可能比较难理解。。。
发帖注意事项
请勿胡乱发帖:https://www.right.com.cn/forum/thread-8307840-1-1.html
账户手机验证:https://www.right.com.cn/forum/home.php?mod=spacecp&ac=plugin&id=jzsjiale_sms:home
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|