Python编写定时运行脚本代码
来源:岁月联盟
时间:2010-09-24
- import sys
- import os
- import datetime
- import time
- class ArgsDealwith:
- def arg_environment(self, args):
- filepath = (PYTHON_PATH, path)
- for i in filepath:
- filename = os.environ.get(i,"%s is null." % i)
- print %s: % i, , filename
- def arg_en(self, args):
- filepath = (PYTHON_PATH, path)
- for i in filepath:
- filename = os.environ.get(i,"%s is null." % i)
- print %s: % i, , .join(filename.split(;))
- def arg_file(self, args):
- if not args:
- print Error: file name is null.
- else:
- if len(args) == 1 and args[0].lower() == python_path:
- filename = os.environ.get(args[0], None)
- if filename:
- args = filename.split(;)
- else:
- print Error: "%s" is null % args[0]
- exit()
- for i in args:
- if os.path.isfile(i):
- try:
- execfile(i)
- except:
- print Error: "%s" run failed. % i
- else:
- print Error: Not found "%s" file. % i
- def arg_filetime(self, args):
- if not args:
- print Error: file name is null.
- elif len(args) % 2 != 0:
- print Error: args isnt validate
- else:
- fileTimes = [i for i in args if args.index(i) % 2 != 0 ]
- for i in fileTimes:
- try:
- fileTimes[fileTimes.index(i)] = int(i)
- except Exception:
- print Error: time args isnt validate
- exit()
- if i <= 0:
- print Error: time<=0
- exit()
- minTime = fileTimes[0]
- for i in fileTimes:
- if i < minTime:
- minTime = i
- strTime = time.strftime(%Y-%m-%d-%H-%M-%S, time.localtime())
- tupleTime = tuple([int(i) for i in strTime.split(-)])
- begin = datetime.datetime(tupleTime[0], tupleTime[1], tupleTime[2], tupleTime[3], tupleTime[4], tupleTime[5])
- fileTimes = [[i, 0] for i in fileTimes]
- seconds = 0
- while True:
- strTime = time.strftime(%Y-%m-%d-%H-%M-%S, time.localtime())
- tupleTime = tuple([int(i) for i in strTime.split(-)])
- end = datetime.datetime(tupleTime[0], tupleTime[1],tupleTime[2], tupleTime[3], tupleTime[4], tupleTime[5])
- time_sub = end - begin
- seconds = time_sub.seconds
- begin = end
- for i in fileTimes:
图片内容
最近更新
随机推荐
- 马云蔡崇信建个人公益基金 规模达阿里
- Tags! 我需要更多的 RFID tags!
- 谷歌修补Reader安全漏洞 鼓励多举报
- MS09-051:Windows Media Runtime 中的
- Apache Web Server 2.0.47访问控制限
- 国外黑客发现三星5款手机安全漏洞 遭
- Vista再现安全漏洞 未来恐深受影响
- 安全快报:NSLOOKup程序存在0day漏洞(
- 思科证实VoIP电话可被网络远程监听
- COMpfun继任者Reductor可以修改TLS流
- MS05-034:微软ISA Server 2000 的累积
- 马克斯CMS2.0beta (maxcms)SQL注入漏
- 虚拟运营商牌照下月将发放 中移动策略
- CNCERT启动第六次手机病毒专项治理行
- MS08-003:Active Directory 中允许拒
- Windows Active Directory 中存在漏洞
- 微软IIS被发现一个严重安全漏洞
- 压岁钱如何理财:你我贷、余额宝、银
- Microsoft DirectX媒体文件解析存在代
- P2P续演淘金悲喜剧:六天内第3家流动