python根据uuid去重,获取请求重各种动作的次数
2014-12-01 11:28
309 查看
#!/usr/bin/python # -*- coding: utf-8 -*- #RUN // 程序启动 #EXIT // 程序退出 #START // 热点启动 #STOP // 热点停止 #ONL // 客户端上线 #OFFL // 客户端下线 #INSTALL //安装 #UNINSTALL //卸载 import re #模式匹配UUID patternUid=re.compile(r'(\w){8}-(\w){4}-(\w){4}-(\w){4}-(\w){12}') #定义Uid字典,用来排重 uid={} #用来统计各种动作的次数 actionCount={ "a=RUN":0, "a=EXIT":0, "a=START":0, "a=STOP":0, "a=ONL":0, "a=OFFL":0, "a=INSTALL":0, "a=UNINSTALL":0 } for k,v in actionCount.iteritems(): with open("C:/Users/Administrator/Desktop/python/result.txt") as f: for line in f: if patternUid.search(line): uidName=patternUid.search(line).group() if k in line: if uid.has_key(uidName): pass else: uid[uidName]=1 actionCount[k]+=1 uid.clear() for k,v in actionCount.iteritems(): print k ,actionCount[k] ---------------------------------- 结果时间: C:\Python27\python.exe C:/Users/Administrator/Desktop/python/test3.py a=EXIT 42 a=START 404 a=INSTALL 0 a=STOP 228 a=UNINSTALL 0 a=RUN 45 a=ONL 274 a=OFFL 229 total time is : 2.03400015831优化方法二
#!/usr/bin/python # -*- coding: utf-8 -*- #RUN // 程序启动 #EXIT // 程序退出 #START // 热点启动 #STOP // 热点停止 #ONL // 客户端上线 #OFFL // 客户端下线 #INSTALL //安装 #UNINSTALL //卸载 import re import time import sys start_time=time.time() #模式匹配UUID patternUid=re.compile(r'(\w){8}-(\w){4}-(\w){4}-(\w){4}-(\w){12}') #定义时间 yesterday=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60)) #定义Uid字典,用来排重 uid={} actionCount={ "a=RUN":0, "a=EXIT":0, "a=START":0, "a=STOP":0, "a=ONL":0, "a=OFFL":0, "a=INSTALL":0, "a=UNINSTALL":0, "a=AUTORUN":0 } with open("C:/Users/Administrator/Desktop/python/28.log") as f: for line in f: if patternUid.search(line): uidName=patternUid.search(line).group() for k,v in actionCount.iteritems(): if k in line: if uid.has_key(uidName+k): uid[uidName+k]+=1 else: uid[uidName+k]=1 actionCount[k]+=1 for k,v in actionCount.iteritems(): print k,v end_time=time.time() print "total time is:",end_time-start_time --------------------------------- 结果时间: C:\Python27\python.exe C:/Users/Administrator/Desktop/python/test4.py a=EXIT 42 a=START 404 a=INSTALL 0 a=AUTORUN 236 a=STOP 228 a=UNINSTALL 0 a=RUN 45 a=ONL 274 a=OFFL 229 total time is: 0.287000179291
本文出自 “记录点滴” 博客,请务必保留此出处http://caozm.blog.51cto.com/1118764/1584955
相关文章推荐
- 关于在python中获取CGI之POST请求data块内容
- python 根据文件内容而不是后缀名 获取文件类型
- python实现根据用户输入从电影网站获取影片信息的方法
- 根据WOS获取某篇SCI论文被引用次数[Web of Science 统计]
- python根据京东商品url获取产品价格
- python+fastcgi+flup获取请求的数据和环境变量
- python 根据标题获取窗口句柄,根据句柄取得进程号,关闭进程
- 在Python3.0中使用HTTPServer处理web请求2-获取请求参数
- python web应用开发中获取各种参数的方式
- python搜索引擎之搜索系统的建立——根据关键字命中次数排分给出前若干个答案
- python 获取当前节点instance UUID
- 使用Python获取Linux系统的各种信息
- 使用Python获取Linux系统的各种信息
- python根据开头和结尾字符串获取中间字符串的方法
- python 获取uuid
- python 根据文件内容而不是后缀名 获取文件类型
- [Python] 根据IP获取位置信息
- python分析nginx根据每日请求量自动屏蔽
- Python 获取根据文件URL 获取文件的基本信息
- [置顶] python语言处理get类型请求,调试模式获取数据代码