import os
####You have to Edit these next two constants to fit your needs!!!####
TrillianLogDirectory = "c:\Program Files\Trillian\Users\default\logs\AIM\\"
AIMLogsDirectory = "C:\Documents and Settings\Galen Maly\My Documents\AIM Logs\Test\\"
######################################################################
def find(str, ch):
index = 0
while index < len(str):
if str[index] == ch:
return index
index = index + 1
return -1
def DayOfWeekConversion(input):
output=""
if(input=="Sun"):
output="Sunday"
if(input=="Mon"):
output="Monday"
if(input=="Tue"):
output="Tuesday"
if(input=="Wed"):
output="Wednesday"
if(input=="Thu"):
output="Thursday"
if(input=="Fri"):
output="Friday"
if(input=="Sat"):
output="Saturday"
return output
def MonthConversion(input):
output = ""
if(input=="Jan"):
output="01"
if(input=="Feb"):
output="02"
if(input=="Mar"):
output="03"
if(input=="Apr"):
output="04"
if(input=="May"):
output="05"
if(input=="Jun"):
output="06"
if(input=="Jul"):
output="07"
if(input=="Aug"):
output="08"
if(input=="Sep"):
output="09"
if(input=="Oct"):
output="10"
if(input=="Nov"):
output="11"
if(input=="Dec"):
output="12"
return output
def FileNameGen(DateLine, Dir, MySN, TalkingTo):
#Looks like: /dir/MySN/TalkingTo/2003-05-06 [Tuesday].htm
DateLine = DateLine.split()
year=DateLine[len(DateLine)-1]
time=DateLine[len(DateLine)-2]
date=DateLine[len(DateLine)-3]
month=DateLine[len(DateLine)-4]
month=MonthConversion(month)
day=DateLine[len(DateLine)-5]
day=DayOfWeekConversion(day)
FileName = Dir
FileName += MySN + "\\"
FileName += TalkingTo + "\\"
FileName += year + "-" + month + "-" + date + " [" + day +"].htm"
#print FileName
return FileName
def LinkCatcher(input):
i=0
output = ""
last=0
slash = ""
while i < len(input)-6:
if input[i] == "<":
output += "<"
i = i + 1;
if input[i:i+6]=="(Link:":
prelast = last
last=find(input[i:],")")+i
print last
if prelast:
slash=""
else:
slash=""
output += input[prelast:i] + slash + ""
i = i + 1
output+=input[last+1:]
if last:
output+= ""
return output
def lowercase(input):
o = ""
for i in input:
if i =="A":
o += "a"
elif i =="B":
o += "b"
elif i =="B":
o += "b"
elif i =="C":
o += "c"
elif i =="D":
o += "d"
elif i =="E":
o += "e"
elif i =="F":
o += "f"
elif i =="G":
o += "g"
elif i =="H":
o += "h"
elif i =="I":
o += "i"
elif i =="J":
o += "j"
elif i =="K":
o += "k"
elif i =="L":
o += "l"
elif i =="M":
o += "m"
elif i =="N":
o += "n"
elif i =="O":
o += "o"
elif i =="P":
o += "p"
elif i =="Q":
o += "q"
elif i =="R":
o += "r"
elif i =="S":
o += "s"
elif i =="T":
o += "t"
elif i =="U":
o += "u"
elif i =="V":
o += "v"
elif i =="W":
o += "w"
elif i =="X":
o += "x"
elif i =="Y":
o += "y"
elif i =="Z":
o += "z"
else:
o+=i
return o
def LineToAIM(line,MySN,TalkingTo):
Outer=""
if lowercase(line[:len(MySN)]) == lowercase(MySN):
Outer+= """""" + MySN + """:"""
line=line[len(MySN)+2:len(line)]
Outer+= LinkCatcher(line)
Outer+= "
"
elif lowercase(line[:len(TalkingTo)]) == lowercase(TalkingTo):
Outer+= """""" + TalkingTo + """:"""
line=line[len(MySN)+2:len(line)]
Outer+= LinkCatcher(line)
Outer+= "
"
elif lowercase(line[:3]) == lowercase("***"):
Outer+= """""" + Outer + LinkCatcher(line) + """"""
Outer+= "
"
elif line[:1] =="[":
time = line[1:find(line,"]")]
line=line[find(line,"]")+1:]
# print "|" + lowercase(line[1:len(MySN)+1]) + "|" + lowercase(MySN) + "|"
# print time
if lowercase(line[1:len(MySN)+1]) == lowercase(MySN):
# print "5"
Outer+= """""" + MySN + " (" + time + """):"""
line=line[len(MySN)+2:len(line)]
Outer+= LinkCatcher(line)
Outer+= "
"
elif lowercase(line[1:len(TalkingTo)+1]) == lowercase(TalkingTo):
Outer+= """""" + TalkingTo + " (" + time + """):"""
line=line[len(TalkingTo)+2:len(line)]
Outer+= LinkCatcher(line)
Outer+= "
"
elif lowercase(line[1:4]) == lowercase("***"):
Outer+= """""" + Outer + LinkCatcher(line) + """"""
Outer+= "
"
else:
Outer+= LinkCatcher(line) + "
"
return Outer
def SingleScreenNameConversion(Input, Dir, OutDir):
OpenLog=0
makedirs = 0
TLog = open(Dir+Input).readlines() #import files
i = 0
while i < len(TLog):
if i==0:
TLog[0]=TLog[0][3:]
if(TLog[i][0:7]=="Session"):
if(TLog[i][8:13] == "Start"):
MySN = TLog[i][15:find(TLog[i],":")]
# print "MySN: |" + MySN + "|"
TalkingTo=TLog[i][find(TLog[i],":")+1:find(TLog[i],")")]
# print "TalkingTo: |" + TalkingTo + "|"
if makedirs==0:
os.system("""mkdir \"""" + OutDir + "\\" + MySN + """\" """)
os.system("""mkdir \"""" + OutDir + "\\" + MySN + "\\" + TalkingTo + """\" """)
makedirs=1
OutputFileName=FileNameGen(TLog[i], OutDir, MySN, TalkingTo)
Out = open(OutputFileName,"a")
OpenLog=1
if(TLog[i][8:13] == "Close"):
Time = TLog[i].split()
Out.write("