Advertisement
PikalaxALT

tppmodbot_format.py

Feb 28th, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. import codecs
  2. def format_modbot_bans(chatlogfile,outputfile,emotelist=None):
  3.     chatlog = [codecs.decode(x,'utf-8').rstrip().split('\t') for x in open(chatlogfile).readlines() if len(x)>1]
  4.     if emotelist is not None:emotes=[x.rstrip() for x in open(emotelist).readlines()]
  5.     for i,x in enumerate(chatlog):
  6.         if x[1]=='-*-':
  7.             tmp=[y for y in x]
  8.             tmp.pop(1)
  9.             tmp.append('-*- '+' '.join(tmp[1].split(' ')[1:]))
  10.             tmp[1] = tmp[1].split(' ')[0]
  11.             chatlog[i]=tmp
  12.         if emotelist is not None:
  13.             tmp = x[2].split(' ')
  14.             KappaCounter = 0
  15.             ind = 0
  16.             LastKappa = None
  17.             for j,y in enumerate(tmp):
  18.                 if y in emotes:
  19.                     if y != LastKappa:
  20.                         KappaCounter=1
  21.                         LastKappa = y
  22.                         ind = j
  23.                     else:
  24.                         KappaCounter+=1
  25.                     tmp[j] = ''
  26.                     tmp[ind] = '({})x{}'.format(LastKappa,KappaCounter)
  27.                 else:
  28.                     KappaCounter = 0
  29.                     LastKappa = None
  30.             while '' in tmp:tmp.remove('')
  31.             chatlog[i][2] = ' '.join(tmp)
  32.                    
  33.     # First pass: Find all the TPPModbot lines
  34.     print("Parsing modbot lines...")
  35.     modbot = {i:[x[2].split(' ')[0][1:], ' '.join(x[2].split(' ')[5:])] for i,x in enumerate(chatlog) if x[1].lower() == "tppmodbot"}
  36.     inds = [i for i in modbot.keys()]
  37.     inds.sort()
  38.     # Second pass: Find the offending post and format it into a file, in order.
  39.     op = [["Time","User","Ban","Post"]]
  40.     print("Finding the offenders...")
  41.     for i in inds:
  42.         for j in range(i):
  43.             if chatlog[i-j][1].lower()==modbot[i][0].lower():break
  44.         if chatlog[i-j][1].lower()==modbot[i][0].lower():
  45.             op.append(chatlog[i-j][0:2]+[modbot[i][1]]+[chatlog[i-j][2]])
  46.     with open(outputfile,'w+') as O:
  47.         stats = {}
  48.         for x in op:
  49.             O.write('|'.join([codecs.encode(y,'utf-8') for y in x])+'\n')
  50.             if x[2] not in stats.keys():stats[x[2]]=1
  51.             else:stats[x[2]]+=1
  52.     stats.pop('Ban')
  53.     return stats
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement