1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

#!/usr/bin/env python # Add up deaths in Minecraft Logs # v 0.1 # Copyright 2014, Andrew J. Bonham #Imports and constants import re import argparse import csv #Parse command line parser = argparse. ArgumentParser ( ) parser . add_argument ( "logfile" , help = "specify a logfile to process" ) parser . add_argument ( "output" , help = "specify an output file" ) args = parser . parse_args ( ) #Read the logfile into a list of lines theLog = [ ] fileObject = open ( args. logfile , 'r' ) for line in fileObject: theLog. append ( line ) fileObject. close ( ) #Setup an output list outputDict = { } #Player List #TODO: Extract names with a regex \w+ search nameList = [ 'mrwynd' , 'Paradoxdruid' , 'duv67' , 'BoulderMeg' , 'chrreev' , 'Moakalot' , 'Siruial' , 'tetriseyes' , 'wolpoff' , 'Davide303' , 'Ryujinamida' , 'SusaBee' ] #Have a set of death messages to match deathMsg = [ "was squashed by a falling anvil" , "was pricked to death" , "walked into a cactus whilst trying to escape" , "was shot by arrow" , "drowned" , "blew up" , "was blown up by" , "hit the ground too hard" , "fell from a high place" , "fell off a ladder" , "fell off some vines" , "fell out of the water" , "fell into a patch of fire" , "fell into a patch of cacti" , "was doomed to fall" , "was shot off some vines by" , "was shot off a ladder by" , "was blown from a high place by" , "went up in flames" , "burned to death" , "was burnt to a crisp whilst fighting" , "walked into a fire whilst fighting" , "was slain by" , "was shot by" , "was fireballed by" , "was killed by" , "got finished off by" , "was slain by" , "tried to swim in lava" , "died" , "got finished off by" , "was slain by" , "was shot by" , "was killed by" , "was killed by magic" , "starved to death" , "suffocated in a wall" , "was killed while trying to hurt" , "fell out of the world" , "fell from a high place and fell out of the world" , "was knocked into the void by" , "withered away" ] #Add names to the Dictionary for name in nameList: outputDict [ name ] = [ ] #Process the logfile looking for death events for line in theLog: for message in deathMsg: diedOnServer = re . search ( message , line ) if diedOnServer: for name in nameList: playerName = re . search ( name , line ) if playerName: chatter = re . search ( r ".* \< .*" , line ) if chatter: #if people chatted using the keywords, exclude it pass else : cause = re . search ( r " \[ (.*) \] \[ Server thread/INFO \] : \w + (.*)$" , line ) if cause. group ( 2 ) : outputDict [ name ] . append ( cause. group ( 2 ) ) #Tally Dictionary tallyDict = { } for key , value in outputDict. items ( ) : if not key in tallyDict. keys ( ) : tallyDict [ key ] = { } else : pass for item in value: if not item in tallyDict [ key ] . keys ( ) : tallyDict [ key ] [ item ] = 0 tallyDict [ key ] [ item ] + = 1 #Write the output to a CSV file with open ( args. output , 'wb' ) as csvfile: writer = csv . writer ( csvfile ) for key , value in tallyDict. items ( ) : writer. writerow ( [ key ] ) for key_ , value_ in value. items ( ) : writer. writerow ( [ key_ , value_ ] )