梨尽兴 | Li's Blog

Back

an image targetting my articlean image targetting my article

代码如下#

import subprocess
import smtplib
from email.mime.text import MIMEText
# 运行 JavaScript 文件def run_js_file(js_file):
    result = subprocess.run(['node', js_file], capture_output=True, text=True)
    return result.stdout.strip()
# 发送邮件def send_email(subject, body, to_email):
    from_email = 'your_email@example.com'  # 替换你的邮箱地址    password = 'your_email_password'  # 替换为你对应邮箱的SMTP密码    smtp_server = 'smtp.example.com'  # 替换为你对应邮箱的SMTP 服务器地址    smtp_port = 587  # 通常是 587 或 465    msg = MIMEText(body)
    msg['Subject'] = subject
    msg['From'] = from_email
    msg['To'] = to_email
    with smtplib.SMTP(smtp_server, smtp_port) as server:
        server.starttls()
        server.login(from_email, password)
        server.send_message(msg)
if __name__ == "__main__":
    js_file = 'path_to_your_file.js'  # 替换为你的 JS 文件路径    result = run_js_file(js_file)
    print("JavaScript execution result:", result)
    # 发送结果到手机的邮件地址    send_email('JavaScript Execution Result', result,'your_email@example.com')
python

需要安装的依赖库如下#

pip install beautifulsoup4
pip install requests
pip install PyExecJS
bash

青龙面板直接在依赖管理处安装就好了。

具体使用#

把上述代码复制,在脚本管理里新建xxx.py文件,点击编辑,粘贴进该文件,并把文件里变量替换为你所需要的,点击保存,在定时任务里新建任务,命令填”task xxx.py”,定时规则推荐”00 22 * * *“,确定后点击运行查看是否设置正确。

运行效果如下图所示#

img

青龙面板每日京豆详情通知
https://ljx.icu/blog/qinglong-jd-notice
Author Ljx
Published at August 19, 2024
Comment seems to stuck. Try to refresh?✨