i have here a python script..
what it does is check for a specific parts of a text file
well, if you know python, i bet you could get what it does
so here is the .py code
Code:
#!/usr/bin/env python
# counters.py script for TR
# usage: counters.py filename [att/def/both]
# filename = file containing copy of guild battle log
# 'att/def/both' = sort counters by attacker or defender
# 'both' shows both, apparently. default is 'att'
# written by Laanders, feel free to share and improve
# Akima - added html outputting
import string
import sys
import os
# 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
# enemy checking
check_enemies=True
show_type=2
if os.path.isfile('enemies.lst'):
check_enemies=True
enemies=[]
efile=open('enemies.lst','r')
for line in efile:
if '(#' in line:
lspl=line.split()
ename=lspl[1]
eid=lspl[2]
emage=ename+' '+eid
enemies.append(emage)
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 "<p><br>-----------------------------------<br>"
print 'Active counters sorted by ATTACKER:<br>'
print "-----------------------------------<br><br>"
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 '<br><strong>\n</strong>','<b>', i ,'</b>','has given counters to:<br>'
for k,v in cond.iteritems():
vstr=str(v)
print k+' ('+vstr+'x)<br>'
print
# sort by defender
if outtype==1 or outtype==3:
print "</p><p><br>-----------------------------------<br>"
print 'Active counters sorted by DEFENDER:<br>'
print "-----------------------------------<br><br>"
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 '<br><strong>\n</strong>',i,'has counters on:<br>'
for k,v in cond.iteritems():
vstr=str(v)
print k+' ('+vstr+'x)<br>'
print
print "-----------------------------------<br><br>"
#for k,v in cnt.iteritems():
# print '\n',k,'has counters on:'
# for j in v:
# print j
filename is counters.py
to run it, you use counters.py br.txt > counters.html
it creates an html doc
what i want is, instead of importing a external file
there will be a text area where the contents of the br.txt
will be pasted
also, the enemy.lst file
instead of importing it, the list will be pasted to a 2nd text area..
love you guys..i hope you can work it out