当前位置:编程学习 > 网站相关 >>

Python编写定时运行脚本代码

  1. import sys
  2. import os
  3. import datetime
  4. import time
  5. class ArgsDealwith:
  6.    
  7.     def arg_environment(self, args):
  8.         filepath = (PYTHON_PATH, path)
  9.         for i in filepath:
  10.             filename = os.environ.get(i,"%s is null." % i)
  11.             print %s: % i, , filename
  12.     def arg_en(self, args):
  13.         filepath = (PYTHON_PATH, path)
  14.         for i in filepath:
  15.             filename = os.environ.get(i,"%s is null." % i)
  16.             print %s: % i, , .join(filename.split(;))
  17.     def arg_file(self, args):
  18.         if not args:
  19.             print Error: file name is null.
  20.         else:
  21.             if len(args) == 1 and args[0].lower() == python_path:
  22.                 filename = os.environ.get(args[0], None)
  23.                 if filename:
  24.                     args = filename.split(;)
  25.                 else:
  26.                     print Error: "%s" is null % args[0]
  27.                     exit()
  28.                
  29.             for i in args:
  30.                 if os.path.isfile(i):
  31.                     try:
  32.                         execfile(i)
  33.                     except:
  34.                         print Error: "%s" run failed. % i
  35.                 else:
  36.                     print Error: Not found "%s" file. % i
  37.            
  38.     def arg_filetime(self, args):
  39.         if not args:
  40.             print Error: file name is null.
  41.         elif len(args) % 2 != 0:
  42.             print Error: args isnt validate
  43.         else:
  44.             fileTimes = [i for i in args if args.index(i) % 2 != 0 ]
  45.             for i in fileTimes:
  46.                 try:
  47.                     fileTimes[fileTimes.index(i)] = int(i)
  48.                 except Exception:
  49.                     print Error: time args isnt validate
  50.                     exit()
  51.                 if i <= 0:
  52.                     print Error: time<=0
  53.                     exit()                
  54.                
  55.             minTime = fileTimes[0]
  56.             for i in fileTimes:
  57.                 if i < minTime:
  58.                     minTime = i
  59.            
  60.             strTime = time.strftime(%Y-%m-%d-%H-%M-%S, time.localtime())
  61.             tupleTime = tuple([int(i) for i in strTime.split(-)])
  62.             begin = datetime.datetime(tupleTime[0], tupleTime[1], tupleTime[2], tupleTime[3], tupleTime[4], tupleTime[5])
  63.            
  64.            
  65.             fileTimes = [[i, 0] for i in fileTimes]
  66.             seconds = 0
  67.             while True:
  68.                 strTime = time.strftime(%Y-%m-%d-%H-%M-%S, time.localtime())
  69.                 tupleTime = tuple([int(i) for i in strTime.split(-)])
  70.                 end = datetime.datetime(tupleTime[0], tupleTime[1],tupleTime[2], tupleTime[3], tupleTime[4], tupleTime[5])
  71.                
  72.                 time_sub = end - begin
  73.                 seconds = time_sub.seconds
  74.                 begin = end
  75.                 for i in fileTimes:
  76. 补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,