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