用Python实现定时关机
Python #定时关机2012-11-25 22:29
实现代码如下:
import os,time;
rh=int(time.strftime("%H",time.localtime()));
rm=int(time.strftime("%M",time.localtime()));
cmd="cmd.exe /k shutdown -s -t 0";
c1=True;
while c1:
try:
h=int(raw_input("Please input the hour:"));
if h>=0 and h<=23:
c1=False;
else:
continue;
except:
continue;
c2=True;
while c2:
try:
m=int(raw_input("Please input the minute:"));
if m>=0 and m<=59:
c2=False;
else:
continue;
except:
continue;
if h==rh:
if m<=rm:
os.system(cmd);
else:
time.sleep((m-rm)*60);
os.system(cmd);
elif h>rh:
tem1=(h-rh-1)*3600+(60-rm+m)*60;
time.sleep(tem1);
os.system(cmd);
else:
tem2=(23-rh+h)*3600+(60-rm+m)*60;
time.sleep(tem2);
os.system(cmd);相关文章
- 用Python实现的简易采集爬虫 2012/11/23
- Python实现QQ登陆 2012/11/23
- 用Python按日期导出所有微信 2012/11/23
- Python使用global语句 2012/11/23
- 说说Python的版本选择、IDE、库 2012/11/23
- Python实现的记事本尾巴(仿QQ尾巴) 2012/11/23
- python写的http客户端测试程序 2012/11/23
- 用python下载网页 2012/11/23
- 用Python来打印日历 2012/11/22
- Python实现115网盘自动摇奖 2012/11/22