This commit is contained in:
Peter Molnar 2018-03-02 13:00:49 +00:00 committed by GitHub
parent de14c33321
commit 8303353a02

View file

@ -8,7 +8,6 @@ import hashlib
import arrow
import argparse
from pprint import pprint
def logfilename(dt, nulltime=False):
@ -36,7 +35,7 @@ def logappend(fpath,dt,sender,msg):
os.utime(os.path.dirname(fpath), (dt.timestamp, dt.timestamp))
def logcreate(fpath,contact, dt,account,plugin):
logging.info('creating converted log: %s' % (fpath))
logging.debug('creating converted log: %s' % (fpath))
if not os.path.exists(fpath):
with open(fpath, 'wt') as f:
f.write("Conversation with %s at %s on %s (%s)\n" % (
@ -143,80 +142,57 @@ def do_trillian(trillianlogs, logpathbase, trilliantz):
contact = os.path.basename(log).replace('.log', '')
plugin = os.path.basename(os.path.dirname(os.path.dirname(log))).lower()
c = ''
try:
with open(log, 'rt') as f:
c = f.read()
except UnicodeDecodeError:
with open(log, 'rt', encoding = "ISO-8859-1") as f:
c = f.read()
with open(log, 'rb') as f:
c = f.read().decode('utf8', 'ignore')
for session in SPLIT_SESSIONS.findall(c):
participants, timestamp, session = session
logging.debug('converting session starting at: %s' % (timestamp))
participants = participants.split(':')
account = participants[0]
dt = arrow.get(timestamp, 'ddd MMM DD HH:mm:ss YYYY')
dt = dt.replace(tzinfo=trilliantz)
fpath = os.path.join(
logpathbase,
plugin,
participants[0],
contact,
logfilename(dt)
)
for session in SPLIT_SESSIONS.findall(c):
participants, timestamp, session = session
logging.debug('converting session starting at: %s' % (timestamp))
participants = participants.split(':')
account = participants[0]
dt = arrow.get(timestamp, 'ddd MMM DD HH:mm:ss YYYY')
dt = dt.replace(tzinfo=trilliantz)
fpath = os.path.join(
logpathbase,
plugin,
participants[0],
contact,
logfilename(dt)
)
if not os.path.isdir(os.path.dirname(fpath)):
os.makedirs(os.path.dirname(fpath))
if not os.path.isdir(os.path.dirname(fpath)):
os.makedirs(os.path.dirname(fpath))
seconds = int(dt.format('s'))
curr_mindt = dt
for line in SPLIT_MESSAGES.findall(session):
# this is a fix for ancient trillian logs where seconds
# were missing
if seconds == 59:
seconds = 0
else:
seconds = seconds + 1
seconds = int(dt.format('s'))
curr_mindt = dt
for line in SPLIT_MESSAGES.findall(session):
# this is a fix for ancient trillian logs where seconds
# were missing
if seconds == 59:
seconds = 0
else:
seconds = seconds + 1
time, sender, msg = line
try:
mindt = arrow.get(time,
'YYYY.MM.DD HH:mm:ss')
except:
time = time.split(':')
mindt = dt.replace(
hour=int(time[0]),
minute=int(time[1]),
second=int(seconds)
)
time, sender, msg = line
try:
mindt = arrow.get(time,
'YYYY.MM.DD HH:mm:ss')
except:
time = time.split(':')
mindt = dt.replace(
hour=int(time[0]),
minute=int(time[1]),
second=int(seconds)
)
# creating the filw with the header has to be here to
# avoid empty or status-messages only files
logcreate(fpath, participants[1], dt, account, plugin)
# logging.info('creating converted log: %s' % (fpath))
# if not os.path.exists(fpath):
# with open(fpath, 'wt') as f:
# f.write("Conversation with %s at %s on %s (%s)\n" % (
# ,
# dt.format('ddd dd MMM YYYY hh:mm:ss A ZZZ'),
# account,
# plugin
# ))
# creating the filw with the header has to be here to
# avoid empty or status-messages only files
logcreate(fpath, participants[1], dt, account, plugin)
logappend(fpath, mindt, sender, msg)
logappend(fpath, mindt, sender, msg)
# with open(fpath, 'at') as f:
# f.write("(%s) %s: %s\n" % (
# mindt.format('YYYY-MM-DD HH:mm:ss'),
# sender,
# msg
# ))
# os.utime(fpath, (mindt.timestamp, mindt.timestamp))
# os.utime(os.path.dirname(fpath), (mindt.timestamp, mindt.timestamp))
if params.get('cleanup'):
print('deleting old log: %s' % (log))
os.unlink(log)
if params.get('cleanup'):
print('deleting old log: %s' % (log))
os.unlink(log)
@ -259,23 +235,7 @@ def do_skype(skypedbpath, logpathbase):
os.makedirs(os.path.dirname(fpath))
logcreate(fpath, r[1], dt, account, 'skype')
# if not os.path.exists(fpath):
# with open(fpath, 'wt') as f:
# f.write("Conversation with %s at %s on %s (skype)\n" % (
# r[1],
# dt.format('ddd dd MMM YYYY hh:mm:ss A ZZZ'),
# account
# ))
logappend(fpath, dt, r[3], r[4])
# with open(fpath, 'at') as f:
# f.write("(%s) %s: %s\n" % (
# dt.format('YYYY-MM-DD HH:mm:ss'),
# r[3],
# r[4]
# ))
# os.utime(fpath, (dt.timestamp, dt.timestamp))
# os.utime(os.path.dirname(fpath), (dt.timestamp, dt.timestamp))
if __name__ == '__main__':