python単純分析ログ
1143 ワード
質問:uidが異なるpython統計で「a=RUN」の回数
#!/usr/bin/python
# -*- coding:utf-8 -*-
##exapmle: ‘a=RUN’ , UID
##123.234.40.34 - - [21/Apr/2014:11:22:51 +0800] "GET /aaa.php?uid=S-1-5-21-1629627082-3848928471-3880619898-500&a=OFFL&c=24120947886984&v=1.12.144 HTTP/1.1" 444 0 "-"
import os
import sys
import time
import re
###
c1=0
d1={}
re1=r'uid=(.*?)&'
yesterday=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60))
###
fileHandle=open(sys.argv[1],'r+')
fileList=fileHandle.readlines()
###
for fileLine in fileList:
### ‘a=RUN’ , UID
if fileLine.find('a=RUN') != -1:
### , UID , list , uid
uid = re.findall(re1, fileLine, re.S)
if uid[0] in d1 :
d1[uid[0]]+=1
else:
d1[uid[0]]=1
c1+=1
print 'RUN = %d' % c1
fileHandle.close()
###
result=yesterday+' RUN= '+str(c1)+'
'
anlyResult=open('anlyResultFile.txt','a')
anlyResult.write(result)
anlyResult.close()