【发布时间】:2021-09-10 21:30:41
【问题描述】:
我已经编写了我的第一个脚本,我想每天从我的计算机上的 Windows 调度程序运行它。该脚本用于 1) 确定今天的日出和日落时间,以及 2) 相应地调整笔记本电脑的屏幕亮度。
我知道该脚本有效,因为当我在终端中手动执行它或通过启动批处理文件时,它可以完美运行。但是当我尝试设置我的 Windows 调度程序来触发它时,什么也没有发生。此外,即使我从调度程序窗口单击运行而不是等待其触发时间,它也会说它正在运行但没有任何反应。如果在白天运行,我希望看到屏幕亮度逐渐增加。
亮度.pyw:
# importing the module
import screen_brightness_control as sbc
import datetime
from datetime import timezone
import json
import requests
import sys
from suntime import Sun
import time
send_url = "http://api.ipstack.com/check?access_key=68d6a43e7f37d2152f9bb7dc199b87ef"
geo_req = requests.get(send_url)
geo_json = json.loads(geo_req.text)
latitude = geo_json['latitude']
longitude = geo_json['longitude']
sun = Sun(latitude, longitude)
today_sr = sun.get_sunrise_time()
today_ss = sun.get_sunset_time()
print(today_sr)
print(today_ss)
while True:
current_time = datetime.datetime.now(timezone.utc)
if today_ss > current_time > today_sr and sbc.get_brightness() != 100:
sbc.fade_brightness(100, interval=5)
elif current_time > today_ss and sbc.get_brightness() != 0:
sbc.fade_brightness(0, interval=5)
sys.exit()
time.sleep(60)
run_brightness_python.bat
"C:\Users\dannl\AppData\Local\Programs\Python\Python39\python.exe" "C:\Users\dannl\scripts\brightness.pyw"
pause
【问题讨论】:
-
Super User 可能是询问有关使用 Windows 调度程序的更好的地方。