代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Python
】
定时运行脚本
作者:
步山
/ 发布于
2014/11/10
/
754
#coding=utf-8 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 isn't 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 isn't 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: i[1] += seconds for i in fileTimes: if i[1] == 0: self.arg_file( [args[args.index(str(i[0])) - 1] ] ) elif i[1] >= i[0]: i[1] %= i[0] self.arg_file( [args[args.index(str(i[0])) - 1] ] ) if i[0] - i[1] < minTime: minTime = i[0] - i[1] time.sleep(minTime) def arg_help(self, args): strHelp = "Usage: ps [-options] [args...] where option include:" strHelp += """ -? -help print this help message -e -environment print environment path -en print envrionment path per row -f -file:<file> [file2 file3...] execute file(.py) -ft -filetime:<file time> [file2 time2 file3 time3...] execute file(.py) per time, this run not stop, but this command hasn't validate. time(seconds) must is interger and not less than zero""" print strHelp def arg_args(): args_dic = {'arg_help' : ['-?', '-help'], 'arg_environment' : ['-e', '-environment'], 'arg_en' : ['-en'], 'arg_file' : ['-f', '-file'], 'arg_filetime' : ['-ft', 'filetime']} argsCls = ArgsDealwith() if len(sys.argv) <= 1: argsCls.arg_help(sys.argv) else: argsFun = '' for i in sys.argv[1:]: bMath = False for j in args_dic.items(): if i in j[1]: argsFun = j[0] bMath = True break if bMath: break if argsFun: try: getattr(argsCls, argsFun)(sys.argv[2:]) except Exception, error: print error exit() else: print 'Error: "%s" isn't validate arg.' % ' '.join(sys.argv[1:]) del argsCls if __name__ == '__main__': arg_args()
试试其它关键字
定时运行
同语言下
.
比较两个图片的相似度
.
过urllib2获取带有中文参数的url内容
.
不下载获取远程图片的宽度和高度及文件大小
.
通过qrcode库生成二维码
.
通过httplib发送GET和POST请求
.
Django下解决小文件下载
.
遍历windows的所有窗口并输出窗口标题
.
根据窗口标题调用窗口
.
python 抓取搜狗指定公众号
.
pandas读取指定列
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
步山
贡献的其它代码
(
75
)
.
表.视图.函数.存储过程.触发器.主键.外键.约束.规则:
.
索引
.
SqlServer2005数据库字典表结构
.
上传并给图片加水印
.
从一个目录下提取所有的源文件复制到另一个目录下
.
为按钮添加对话框
.
监听浏览器窗口关闭
.
平滑滚动返回顶部
.
SESSION管理类库
.
麻将胡牌听版判断
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3