Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import codecs
- def format_modbot_bans(chatlogfile,outputfile,emotelist=None):
- chatlog = [codecs.decode(x,'utf-8').rstrip().split('\t') for x in open(chatlogfile).readlines() if len(x)>1]
- if emotelist is not None:emotes=[x.rstrip() for x in open(emotelist).readlines()]
- for i,x in enumerate(chatlog):
- if x[1]=='-*-':
- tmp=[y for y in x]
- tmp.pop(1)
- tmp.append('-*- '+' '.join(tmp[1].split(' ')[1:]))
- tmp[1] = tmp[1].split(' ')[0]
- chatlog[i]=tmp
- if emotelist is not None:
- tmp = x[2].split(' ')
- KappaCounter = 0
- ind = 0
- LastKappa = None
- for j,y in enumerate(tmp):
- if y in emotes:
- if y != LastKappa:
- KappaCounter=1
- LastKappa = y
- ind = j
- else:
- KappaCounter+=1
- tmp[j] = ''
- tmp[ind] = '({})x{}'.format(LastKappa,KappaCounter)
- else:
- KappaCounter = 0
- LastKappa = None
- while '' in tmp:tmp.remove('')
- chatlog[i][2] = ' '.join(tmp)
- # First pass: Find all the TPPModbot lines
- print("Parsing modbot lines...")
- modbot = {i:[x[2].split(' ')[0][1:], ' '.join(x[2].split(' ')[5:])] for i,x in enumerate(chatlog) if x[1].lower() == "tppmodbot"}
- inds = [i for i in modbot.keys()]
- inds.sort()
- # Second pass: Find the offending post and format it into a file, in order.
- op = [["Time","User","Ban","Post"]]
- print("Finding the offenders...")
- for i in inds:
- for j in range(i):
- if chatlog[i-j][1].lower()==modbot[i][0].lower():break
- if chatlog[i-j][1].lower()==modbot[i][0].lower():
- op.append(chatlog[i-j][0:2]+[modbot[i][1]]+[chatlog[i-j][2]])
- with open(outputfile,'w+') as O:
- stats = {}
- for x in op:
- O.write('|'.join([codecs.encode(y,'utf-8') for y in x])+'\n')
- if x[2] not in stats.keys():stats[x[2]]=1
- else:stats[x[2]]+=1
- stats.pop('Ban')
- return stats
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement