过滤tlog某个时间段内(注册并指定行为)的日志
1 #!/usr/bin/env python 2 #_*_ encoding: utf-8 _*_ 3 4 #拉取关键字tlog 5 import os,sys,time,datetime,copy,codecs 6 7 keyword = sys.argv[1] #关键字 8 begin_times = sys.argv[2] #开始时间 9 end_times = sys.argv[3] #结束时间 10 11 func = 'PlayerRegister' 12 tlog='tlog.log' #T_log文件名 13 14 def master_plate(demo): #模版 15 result0 = [] 16 with open (tlog,'rb') as f: 17 for i in f: 18 if i.startswith(demo): 19 dtEventTime = i.split('|')[2] #注册时间 20 vopenid = i.split('|')[6] #用户OPENID号 21 if begin_times <= dtEventTime <= end_times: 22 result0.append(vopenid) 23 24 return list(set(result0)) 25 26 def Player_Register(): #注册 27 result = copy.deepcopy(master_plate(func)) 28 return result 29 30 def Key_word(): #关键字 31 result1 = copy.deepcopy(master_plate(keyword)) 32 return result1 33 34 def Dis_Only(): #去重 35 result = Player_Register() 36 result1 = Key_word() 37 result2 = [] 38 39 for num in result: 40 for i in result1: 41 if num == i: 42 result2.append(i) 43 return list(set(result2)) 44 45 46 def main(): 47 with open (tlog,'rb') as f: 48 for i in f: 49 if i.startswith(keyword): 50 dtEventTime = i.split('|')[2] 51 vopenid = i.split('|')[6] 52 if begin_times <= dtEventTime <= end_times: 53 for ii in result3: 54 if vopenid == ii: 55 print i, 56 if __name__ =='__main__': 57 result3 = Dis_Only() 58 main()
posted on 2017-09-09 15:07 augustyang 阅读(429) 评论(0) 编辑 收藏 举报