Python编写定时运行脚本代码
- 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:
补充:Web开发 , Python ,