Created
          July 31, 2012 09:17 
        
      - 
      
- 
        Save syshack/3215371 to your computer and use it in GitHub Desktop. 
    v3
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env python | |
| '''logfomat:2012-07-19 13:50:39,playerId:68719476740,operFlow:1,operType:0,indentify:ws:shanbiP110,sampleId:ws:shanbiP1,Level:1,Exp: | |
| 0,Num:1''' | |
| import re | |
| import time | |
| Time="2012-07-31 12:43:40" | |
| time_str=time.mktime(time.strptime(Time,"%Y-%m-%d %H:%M:%S")) | |
| def grep(file,exp): | |
| fd=open(file,'r') | |
| lines=fd.read().splitlines() | |
| fd.close() | |
| logs=[] | |
| for line in lines: | |
| if re.search(exp,line): | |
| logs.append(line) | |
| return logs | |
| def parse(): | |
| logs=grep('tattoo.log','68719510075') | |
| tattoo_dict={} | |
| up_dict={} | |
| tattoos={} | |
| for log in logs: | |
| lines=log.split(',') | |
| log_time=time.mktime(time.strptime(lines[0],"%Y-%m-%d %H:%M:%S")) | |
| if log_time<=time_str: | |
| d={} | |
| for i in lines: | |
| d[i.split(':')[0]]=i.split(':')[1] | |
| tattoo=lines[4].split(':')[2] | |
| operFlow=int(lines[2].split(':')[1]) | |
| if operFlow !=0: | |
| tattoo_num=int(d['Num'])*int(d['operFlow']) | |
| tattoo_dict.setdefault(tattoo,0) | |
| tattoo_dict[tattoo]+=tattoo_num | |
| elif operFlow==0: | |
| pre_up=tattoo | |
| post_up=lines[5].split(':')[2]+lines[6].split(':')[1]+lines[7].split(':')[1] | |
| if post_up not in pre_up: | |
| up_dict.setdefault(pre_up,0) | |
| up_dict.setdefault(post_up,0) | |
| up_dict[pre_up]+=int(d['Num'])*-1 | |
| up_dict[post_up]+=int(d['Num']) | |
| log_dict=tattoo_dict | |
| for k in up_dict: | |
| log_dict[k] = log_dict.get(k, 0) + up_dict[k] | |
| tattoos["tattooBeans"]=log_dict | |
| tattoos["playerId"]="68719510075" | |
| return tattoos | |
| print parse() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment