用Python实现定时关机
Python #定时关机2012-11-25 22:29
实现代码如下:
01 | import os,time; |
02 | rh = int (time.strftime( "%H" ,time.localtime())); |
03 | rm = int (time.strftime( "%M" ,time.localtime())); |
04 | cmd = "cmd.exe /k shutdown -s -t 0" ; |
05 | c1 = True ; |
06 | while c1: |
07 | try : |
08 | h = int ( raw_input ( "Please input the hour:" )); |
09 | if h> = 0 and h< = 23 : |
10 | c1 = False ; |
11 | else : |
12 | continue ; |
13 | except : |
14 | continue ; |
15 | c2 = True ; |
16 | while c2: |
17 | try : |
18 | m = int ( raw_input ( "Please input the minute:" )); |
19 | if m> = 0 and m< = 59 : |
20 | c2 = False ; |
21 | else : |
22 | continue ; |
23 | except : |
24 | continue ; |
25 | if h = = rh: |
26 | if m< = rm: |
27 | os.system(cmd); |
28 | else : |
29 | time.sleep((m - rm) * 60 ); |
30 | os.system(cmd); |
31 | elif h>rh: |
32 | tem1 = (h - rh - 1 ) * 3600 + ( 60 - rm + m) * 60 ; |
33 | time.sleep(tem1); |
34 | os.system(cmd); |
35 | else : |
36 | tem2 = ( 23 - rh + h) * 3600 + ( 60 - rm + m) * 60 ; |
37 | time.sleep(tem2); |
38 | 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