【Time系列二】自动关机脚本

今天在弄那个自动关机脚本的时候,遇到最大的麻烦就是怎么像电脑一样显示关机时间,看

了其他大神的博客,明白了原来用的是我没学过的datetime模块和time.strptime模块 ! ! !

接下来,就让我们一点点来实现它!

参考出处: http://www.xinghaixu.com/archives/685

其实说的那么高端(装逼)的自动关机, 就是调用系统的shutdown命令,当我们导入os模块时

,就把电脑的一些系统命令都导入进去了! 比如: 可以试试os.system("inconfig"), 执行后是这样的 !

是不是和启动命令行(按 Win+R —> cmd )再输入config是一样的?

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlEAAADGCAIAAAB94kJbAAAN6ElEQVR4nO3cW3brtg4AUM1/VBra/Wivq4gECFJ2Ytl7f3TZFAFCDxNxTla3DQAAAAAAAAAAAAAAAAAAAHh7+74/cRoAvMo+bznDH5wewPew1db9c6GGl6vb846vT2+TQABK2maWfAV5+lp/Ivna9JRvVHoewJsq9rwXrfUnpnreVMHd8ChDt+edQo5vL3ZiAL6x5/2jW0zUAus5t+Z7Xr3nFee8zzUEuJlhz0u+XrRfQaL8x2ndo8O+W48tqvS8aFqScwt6Xnet7upDxWIAOGsb0mljTXbb4Y6cTxge6tY5jJ098XxwKvme9ryFmttiipUA0PHYfNsX3Wnt4HFzf+7bqICLnWl4RtEJVnJucc+bKixSTAJAx2MnbV90p+WDz+pbeVVPaQDJGS23mdP8Y4Z6nmSmngdwyR173tZrTqWzrZ3Rctru/IWel5iqB4Afht3lNC0f7Pat5aPFHX+5PxVPcypnNDjV8xYOATD26p538W235+Xrzp74xTxteLfsetooycXaABh0l+6E06E2W568nnkPOmIeu3DKyRlN6cbuQc+LFkoKuFIbANtW+5VjsUMk4cPkbVXJ2zw29/49L7FcGwA8U9Koon7fTZLkf2a5ALAs72H597b8653vfAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALyZfd/3ff/rK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A0NTPBVemFX82Wf45xU83AJT8Tqt49SoaHgAAAAB8sxf9hvBZaYt/BQMA/T8YOU3Y0i4y9TeZ+bqJPFWbOZkPwJfamz/r7/a8drw7Zzh4PFrsTMNpp1QaHgB9x1aXfM/b3rjnbbUigScq/hrmY2L5EG23iHrecuboaP79LPreObWohxteYW98diyfY6rn1Z+S4SN1amlJGd087eN7TOiZhtc5fb6mPm53jOWjRM0j6ijdDFHa4brdyXvQBYcnUpkGXNR+umd7z71i+UxTLW2r/b9N8+WinndaVM+Dt3LHvqXncdb9XpV0tTawHUwChz2vW89sGfVw+E4LW/8jpH3xkbF8lL1xOrqN2sZTet7W67Xd/G3BFUn98M0WPiBX+scdY/lM3du/v77n7U1v2+NeOCzDQwyv1naLhd5zo1g+0/5/p8Ftpue1P0BFse1y7Vr1NtZ2UOBF7ti39Dy2Lfg7lO7r5OFo50TZukt3Ux3fFnvecEXgKU4f3u5n+ZNi+RxRy2mbzbDnRd0xerCmHtapCZXMVx53sWLF7o165neO5fPtvY51Gjwe6mY4HmqnTT2XUYVTR4fJf3+PECv2w2KHzWN46A1j+Xz7z3+BezwK7TMRPSjHwfpTWH/skmn5IY81AD8M29hpfOHQdvjxqjh/OK0S7mc6ADJrHeI3m4oeBgAAAAAAAAAAAAAAAAAAAAAAAABwc/8Db76Bxs0dXoYAAAAASUVORK5CYII=" alt="" />

-------------------------------------------------------------------------------------------------------------------

1. 所以第一步就是, 使用shutdown -s -t *

(*表示秒数,比如shutdown -s -t 3600,就是1小时后关机)

 # coding: utf-8

 import os

 setting = raw_input("Setting: ")
os.system("shutdown -s -t %s" % setting)

2. 接下来,当然是明白各个模块的用法啦!

还记得上一篇我们说过, 打印出当前系统时间有两个方法, 一个是按 "周-月-日 时/分/秒 年"

输出的time.ctime(), 一个是按自设的格式输出的time.strftime()

 # coding: utf-8

 import os
import time # 按"周-月-日 时/分/秒 年"的格式显示
print time.ctime() # 按自行设置的格式显示日期
print time.strftime("%H:%M:%S")
print time.strftime("%a %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Z0BwMdjkwAAAAA+1T88Rz7pHs/arQAAAABJRU5ErkJggg==" alt="" />

3. 时间戳与时间转换

怎么给定一个时间,比如2.5个小时后,我要它关机呢?想想看,当然是把2.5 * 3600转化为秒,

再用shutdown命令关机,如果是这样,那倒没什么难的,问题是,我们要这样的效果! 精确显示关机的

时间......这就需要一些模块来转换时间了!

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUEAAABvCAIAAAD9veWUAAAZeUlEQVR4nO2dfXhU1ZnAj7Z9nt2n25a5MxNs0bq1S7e7bXfdJ7PT0bW4gkaL3W4BP6ACQ24mVoSqKKAIwTUES0KoWGskQNi2ikkGyIwJisAk4SMCkYw0HyTYZBAKK5hP8gkkoPvH/Trn3HPuvTOJkKvveX5/ZO7Hue855/2dc+7F5xEdhwIFymgqH3744YkTJ06ePHny5MlTp06dPn36o48+OnPmzNmzZ1tbW9vb2zs6Orq6us6dO9fd3d3T04NO6wqCAgXKKCvt7e3t7e2dnZ24vT09Pb29vehjrKg3fAoFCpRRU1Qxu7u7cXv7+vr6+vpQp1LAXihQRnORDFXVVYtstnT6k08+BQBg1CJ5qtrb39/f39+Pent7e3t7EUKfQIECZdQX3GF5He7r61MWYShQoIz2ItnajxXU398PAkOBYqOCEJI+a4HDUKDYsiCEzp49q2oMDkOBYrMiOaxqDA5DgWKzghCqqalRNQaHoUCxWZEcljQGh6FAsV9BCL3++uvqUgwOQ4Fis6I6LGksO3zp0idA3FRGUHKkjHtB55oZ+SjjeHx1xqI+ozqxmmdEj7HOHtsUNIwKSJC3396Rl5eXl5e3bt26qxuJ5LC6FA/X4aGhy+fPXxwcvDQiwZVl4KlplKk0lRGUnB+oJA/Gor7k4JrYZ9WVxyojvmQDS7kOH9sU5N4Vi/qS800kjEV9eGMrI3httMOVEd+mzs+oB75oVFW9u2HDBsnkeO/Nw4rxQVMQQqtWrRoxh/966nRV1XunTv3fCPRRLOpLzvdlHJelZWrJQ39xZQQl56OM6DGuw8cDyfkobgi7DBc9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oZxarPIXPU6ND5yLPxCYLOKzUOUYnybhqSanypNNzicbE2GB9rfryaOuBQ2uJ+vdC+rcC+pdC+rcC2rdT7zvfiKa9HhN0uOHxz5+OOmx6qTHDiX9+kDS/HfHzqtKmr8/ad7epEf3jJ1bkfSrSNLDu5PSdyUF3klKezsp7S132na3WOZOLXWnvumeE0ryb3P7t7r9W9yzg+5Zxe5ZRe6Zhe6Zb+jYnGSGWwd5wesS8WqMEPqad47jjoXuKWuvm/kag4c0vukPyszZ+s05W/8fZ8Ofg7DebKwAAAAASUVORK5CYII=" alt="" />

 # coding: utf-8

 import time
import datetime # str to datetime.datetime
currtime = time.strftime("%Y-%m-%d %H:%M:%S")
dt = datetime.datetime.strptime(currtime, "%Y-%m-%d %H:%M:%S") # datetime.datetime to time stamp(时间戳)
time_stamp = time.mktime(dt.timetuple()) # time stamp to str
# 到这里时间戳又可以变回来了—日期
time = time.strftime("%H:%M:%S", time.localtime(time_stamp)) print currtime
print dt
print time_stamp
print time

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAiIAAABQCAIAAACro4meAAAEr0lEQVR4nO3cQZLbOAwFUN3/VD7abLoyHVEEIUKUFfu9VdsiPyFOFZBMVWfbAOAGr1/OPv2zYCJ5aVXTyVv4RpXkp93Gq+Nw2dmCAX7EXSb/9GzyuqquSs5nPqfmU8ntxt32ym0AbNuvPjLxcQvb0HDvuqqmk+M3embN9eTM0WdvA6Cr7Vm9pxNfTtQwXdVE8kRgMnldzdcmV5YBjO3+6Lp0zLwawd62qt7HSnK++N7rxDXPHbE6+fCi5gIBIkFTbn9oN/a+7LWwoMcNz233xk8veaNYnFw5d3Vy767ivQDnHHaZG1pYUEx87u/MfHjljSrJ9ZtckXy45pLbAPhLvr+cbY67bpjsVslzk08nkicaa5x89o3uSc6cVQwEiAZAfcwMlwUl5fcaM3PJmbOKgcC3C2ZM+7S3OPhyuHfi3HXJ8Rs9s+Zn3gbAj1dHsKAXkgmvFHZPcvxGq2ueu8l1yf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IVejfzT32uekxzvBeBumX4ddO3ho/uT470AAAAAAAAAAAAAAAB8sv8A+p4rPLTghjoAAAAASUVORK5CYII=" alt="" />

看到没,这里关键的地方就是时间戳,意味着可以把当前的时间转换为秒数,这个秒数是从格林

尼治的1970年1月1日子夜(0点)算起的,由于北京是东八区,所以是从凌晨8点算起的,这些都不重要

,重要的是,只要我们在时间戳这里,把我们要的几小时后关机的小时数转换成对应的时间戳, 那么,

不就可以显示出几小时后的系统时间了么?

【注意: 在其它语言里面的时间戳大部分都是指总毫秒数而非python的总秒数】

----------------------------------------------------------------------------------------------------------

4. 示例

    方法1:利用上面说的原理进行时间戳的转换(麻烦)

我们给完整版加个取消计划关机的功能,其实也是利用系统自带的 "shutdown -a" 命令 !

 # coding: utf-8

 import os
import time
import datetime print u"亲爱的小主,你想要设置你的电脑几小时后关机?"
setting = raw_input("Setting: ")
setting = float(setting) * 3600
# 把当前时间格式化成 "年/月/日 时:分:秒" 的格式(str类)
currtime = time.strftime("%Y-%m-%d %H:%M:%S") # 把str类的时间弄成datetime.datetime类的
dt = datetime.datetime.strptime(currtime, "%Y-%m-%d %H:%M:%S") # 把datetime.datetime类弄成时间戳(time stamp)
time_stamp = time.mktime(dt.timetuple())
shuttime_stamp = time_stamp + setting # 把时间戳弄成str型的时间
shuttime = time.strftime("%H:%M:%S", time.localtime(shuttime_stamp)) # 之所以要时间戳, 就是要把关机后的时间在这里打印出来
print u"您的爱机将在%s关机..." % shuttime os.system("shutdown -s -t %s" % int(setting))

几小时后关机

【Time系列二】自动关机脚本

-------------------------------------------- Perfect ---------------------------Q ^ Q 完美匹配 ! !!

不过缺点嘛就是只能指定当天关机时间, 因为当设置的关机时间早于当前系统时间时, 两者相减

去的时间的绝对值加上当前系统时间,将会导入计算的时间出错,因为我们设置的是当天的 "年/月/日",

(具体大家自己尝试)!

 # coding: utf-8

 import os
import time
import datetime print u"可爱的小主,你想要你的电脑几点关机?" # 将设置的时间格式化成指定格式的字符串
# 这里如果只设置成 "时:分:秒", 后面会出现溢出错误! ! !
setting = time.strftime("%Y-%m-%d ") + raw_input("Setting: ") + ":00" # 把当前的时间(str类)赋值给currtime
currtime = time.strftime("%Y-%m-%d %H:%M:%S") # 把str类转化成datetime.datetime类
dt = datetime.datetime.strptime(currtime, "%Y-%m-%d %H:%M:%S")
curr_dt = datetime.datetime.strptime(setting, "%Y-%m-%d %H:%M:%S") # 把datetime.datetime类的变量转化成时间戳(time stamp)
time_stamp = time.mktime(dt.timetuple())
curr_time_stamp = time.mktime(curr_dt.timetuple()) # 把时间戳转化成时间(str类)
seconds = time_stamp + curr_time_stamp
minus = abs(curr_time_stamp - time_stamp) os.system("shutdown -s -t %s" % int(minus)) print u"您的电脑将在%s关机..." % setting ifshutdown = raw_input("If abolish:")
if "y" in ifshutdown:
os.system("shutdown -a")

指定某时某分关机

abs()是求绝对值

升级版增加了取消关机和设定更精确时间关机的功能,具体功能大家可以自行扩展......

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYcAAAA9CAIAAADJWjKOAAAJbklEQVR4nO1bW5bsOAjL/leVpc3X5LqMEAI76XqgjzkpG8RLpLpvnzmORqPR+BSc57mL5wK3UQ6VcA+4LKJWmk6uxM3msHFGkzshubVROgppQPuQ5E3qfWsUVGuh8HgjfOwV87AaplikdaGN4jsyeDlkc4acxLemDduEbHS9P3oaNS8x20WGr4Iqdu07LdVNwpksou51PDtyLj54QgzEzMOgJO7KjDZqQ1RjmGF20DUSXrgSqFDvF2LxBeHNgNNCy8KipsxE3406sAq7dFaIOzWN9M3aHEPnQ93vmlFWG0oIZTrQJjtWpVE8elm9Yr3ZxD4MtrDCDA5tHuNaTj1d18E67hsz7LBSLLTUHb3o8HxyXJzRmdSGZwl5FIbwMEuywuD1qlavPoUPxlTYxiLD2VwLEPp6V2K2cKOeGa3lt7GI/qzByEZa5/WWV7prRiGgNnivlHBb8tTtiZa4tMr1Ti4kxGeDN4KrJ4T1teRe971sYcLZ2Tw2yyvQ+GBtPF9rMIl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966OiDu7WEfRjogbb2xtGK+NNrw27F7TdZ56AFCoq/to9erVoudm712OFe0vdYm/4X///B91dTs+//x/49BNHRF3drE7f7+kNFNaHuqLa8MouxjlR9q4hu/3Zhcj0xDuaS6YPMO7luUUo2z+5CVKzrhRoiqfCKOtI+LFridCEjvB4CwJmGf9+reUvxsaIjE4KUL5HJveZ+Nu+NGjx9955+0tNb+rrf2wp+dM/zqLWrH19VP7rHzTtiagda+mWsTaaHyKUZpgMGbRvexwldGJRt6MSIs8WSc2KUQN15spgP6zfPnyd999T/m4b197zNv15axitpJ4Gt7be3bnzl3vVC77ZLf93b8U7d37t/70lOikvJ/U2Z8ri1h0uxu1URSGva5W5aumBhzDhov1qGYNatEmP9aGEXVkqA2ztxiaM0tVPkda+aWAYjj3SiB+iB7W1X0kfoxEdsUs51mV5DHUEE/DDx06snHj+3vqf/zVV6i53lldvbmz81iMPSUtaJLhVfnFlAzE+VzczK/pOivPC95axYr9Xuwn8vwpLbCkOWY36qxTfTQeLcPJVwz6vcE23MCbBXjTNpCUlpaJNjY0RPBdemx+nsUkj+32uBl++nRvTc2HH2x8pvPQf3T985v/2DdkW+2LTU1tfX3nTIclbSbDkpzRJO5aliNlM65H25oAZpq82quskF6D5UTaopt2dd5HZwQlEu4arl6Ez8qxSTVrGL4/elTWfVvON1w1bUVbEcupBIgHK1eujMsGWyRRDD9w4O8f1VV3NF359MJ7582b89LSCc01V324+f0vvjhktirZXlI2acmlDO9allNMp7g4I6xhWqGkPm/d67fh2IZCew0n2qsVkt75nzqHM7qO2b2xpAtgEKbhq1at6mc9MUTCNbyv95xxerpPb98e2b39iROHvr5g/kxBeLggf8KJT+17t76wu7G5p/u0qdpkOrzZxe6Szr7ec329nf6cYpQdrpJ/FdO0tbeztUR8Q95B314TRtnF3hrselmAVqMPPdfXHnFjlVB19tWEUXbA347fTsXZ6c/BY6M+YrRLlkYfzW+Lftj0RwK562IYEcAEitWUpWZriPl2kfgYHons2vNxzeH2oX3HL56XN+W2KXc9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azhWnjF6b97LdpP/tt2q2/td/6m7RbfpN2y2/stzxpH/ekfdz8tJvnp938q7Sbfpl20xNpNz6eeuPjqTc8lnrDo6lj56WOnZc6Ni917COpYx5OHT1X5qHUUb/QZzQJ65o0FbFJjhCyXXO3fZTXPsprH00yao7CJRMXigy70z/sTn/Wvb9HjgUNIulM5u9In7/D/vhm+2Nb7I9tSX0w0H/SNPBwScXhVe7RgV35LAm7GdJYmLqYSy5FOc1Mg5RR2GcQpOlTaoZ1FPYZ6+wz1tJMX2ufvtaeo8d0NW/ac95Mz3nDkfNG+gN/Ts/5c/oDrzseeM3xwGsZ017LmFaSMe1Vx/2rHfetyrhvVca9Kx33rsi4d0XGPa9k3P0Hx12/d9z1suOulxx3/s7x82WOny9Lv8OffsfS9NuL0qf6HFOXOKb+T/rUF9KnLE6/rTD9tkXpkxelT16UPqkA43kHj8nPOyY/nz6JDfOWGCRHCNmuvd8+em7mpOdkniV5JnPSM5mTnv323S+LDLt/xbD7V/w/D6EK91Gfd8sAAAAASUVORK5CYII=" alt="" />

如果回复出现"y"取消的话:

【Time系列二】自动关机脚本

    方法2:其实之前一直被时间戳给套住了,根本就可以不用它。简单地在小时和分钟,秒上面做加减就行了

老规矩,先从简单地开始

 # coding: utf-8

 import os
import time # raw_input()产生的是字符串,要转化成int才能加减
print u"亲爱的小主,你打算几个小时后关掉您的电脑!"
hours = raw_input("Setting: ")
seconds = int(hours) * 3600 hours = int(time.strftime("%H")) + int(hours)
shutTime = str(hours) + time.strftime(":%M:%S") print u"您的电脑将在%s关闭" % shutTime
os.system("shutdown -s -t %s" % seconds) isExit = raw_input(u"是否取消?(y/n) ".encode("gbk")) if "y" in isExit:
os.system("shutdown -a")

几小时后关机

结果和上面的例子没什么两样,这里就不再截图了。

 # coding: utf-8

 import os, re, time

 # 我们输入的是hh:mm的格式,所以用正则表达式按冒号分割成时间列表
# 当前时间一定要放在raw_input()之后,因为输入时间会消耗时间,而
# 变量curr_time数据一旦储存,就不会再变化。会产生时差。
print u"亲爱的小主,几时关闭您的爱机呢?"
shut_time = raw_input("Setting: ")
shut_time_list = re.split(":|:", shut_time) shut_hour, shut_min = shut_time_list curr_time = time.localtime()
curr_hour = curr_time.tm_hour
curr_min = curr_time.tm_min
curr_sec = curr_time.tm_sec # 距离关机的总秒数 = 设置时间当天过去的秒数 - 当前时间当天过去的秒数
sec = int(shut_hour) * 3600 + int(shut_min) * 60 -( curr_hour * 3600 + curr_min * 60) - curr_sec
print u"您的爱机将在%s关机" % shut_time
os.system("shutdown -s -t %s" % sec) is_shut = raw_input(u"是否取消?(y/n) ".encode("gbk")) if "y" in is_shut:
os.system("shutdown -a")

某时某分关机

------------2017/1/12深夜

上一篇:配置MySQL使用HugePages


下一篇:ListView+CheckBox两种解决方式及原因分析