I don't know if you could fix this code..
but there is something wrong with it or with me..
i don't know which..
here is the code for the .py script
import string
import sys
# input
if len(sys.argv) < 2:
print "Not enough arguments, quitting."
quit()
if len(sys.argv) > 3:
print "Too many arguments, quitting."
quit()
print "Reading from input file: %s \n" % sys.argv[1]
file=open(sys.argv[1],'r')
try:
outarg=sys.argv[2]
except IndexError:
outarg='att'
if outarg == 'def': outtype=1
if outarg == 'att': outtype=2
if outarg == 'both': outtype=3
#try:
# listarg=sys.argv[2]
# file=open(sys.argv[2],'r')
#except IndexError:
# listarg=False
# reading in
cnt={}
cnt2={}
lastline=' '
for line in file:
if 'sieged' in lastline or 'attacked' in lastline or ') pillaged' in lastline:
lspl=lastline.split()
name=lspl[3]
mid=lspl[4].split('\'')[0]
defender=name+' '+mid
name=lspl[0]
mid=lspl[1]
attacker=name+' '+mid
if ') pillaged' in lastline:
if len(line) < 5: # break loop if line=blank (block, nothing killed)
lastline=line
continue
nspl=line.split()
if nspl[2]=='killed': # break loop if blocked
lastline=line
continue
cnt.setdefault(defender,[]).append(attacker)
cnt2.setdefault(attacker,[]).append(defender)
lastline=line
# condensing data
# sort by attacker
if outtype==2 or outtype==3:
print "-----------------------------------"
print 'Active counters sorted by ATTACKER:'
print "-----------------------------------"
for i in cnt2.iterkeys():
cond={}
for j in cnt2[i]:
if cond.has_key(j):
cond[j]=cond[j]+1
else: cond.setdefault(j,1)
print '\n',i,'has given counters to:'
for k,v in cond.iteritems():
vstr=str(v)
print k+' ('+vstr+'x)'
print
# sort by defender
if outtype==1 or outtype==3:
print "-----------------------------------"
print 'Active counters sorted by DEFENDER:'
print "-----------------------------------"
for i in cnt.iterkeys():
cond={}
for j in cnt[i]:
if cond.has_key(j):
cond[j]=cond[j]+1
else: cond.setdefault(j,1)
print '\n',i,'has counters on:'
for k,v in cond.iteritems():
vstr=str(v)
print k+' ('+vstr+'x)'
print
print "-----------------------------------"
it will be looking for a text that looks like this
Sun May 22 15:02:36 2011
Jing (#101)'s army engaged CaptainCondom (#500)'s army on the battlefield.
Sun May 22 15:04:21 2011
Jing (#101)'s army engaged ReSet (#235)'s army on the battlefield.
Sun May 22 15:05:25 2011
A huge battle rages between the borders of Jing (#101) and HanSoloN (#529)'s country. The massive battle continues everyday, totally blocking traffic.
Sun May 22 15:12:36 2011
A huge battle rages between the borders of PieceOfMind (#71) and Jing (#101)'s country. The massive battle continues everyday, totally blocking traffic.
Sun May 22 15:13:35 2011
A huge battle rages between the borders of Jing (#101) and Meatslap (#103)'s country. The massive battle continues everyday, totally blocking traffic.
Sun May 22 15:20:24 2011
"c"
A huge battle rages between the borders of HanSoloN (#529) and Jing (#101)'s country. The massive battle continues everyday, totally blocking traffic.
Sun May 22 15:58:43 2011
"random.."
GooD (#170)'s army engaged Jing (#101)'s army on the battlefield.
Sun May 22 16:18:23 2011
"R"
wcom (#365)'s army engaged Jing (#101)'s army on the battlefield.
Sun May 22 21:02:43 2011
Ladiesman (#242)'s army engaged Jing (#101)'s army on the battlefield.
Mon May 23 00:07:40 2011
A huge battle rages between the borders of IronMan (#60) and Jing (#101)'s country. The massive battle continues everyday, totally blocking traffic.
Mon May 23 01:04:29 2011
"r"
TheBlackthorn (#523)'s army engaged Jing (#101)'s army on the battlefield.
Mon May 23 05:33:03 2011
Jing (#101)'s army engaged WackoGecko (#243)'s army on the battlefield.
Mon May 23 13:01:36 2011
Jing (#101)'s army engaged Halimar (#346)'s army on the battlefield.
then the result will be look like this
click here
thanks