use datetime.timedelta for Client.onlinetime instead of int
* get rid of all the converting-stuff
This commit is contained in:
parent
89906d04c7
commit
28855e9a81
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from collections import MutableMapping
|
from collections import MutableMapping
|
||||||
|
|
||||||
|
@ -70,12 +71,12 @@ class Client(object):
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
self.onlinetime = 0
|
self.onlinetime = datetime.timedelta()
|
||||||
self.kicks = 0
|
self.kicks = 0
|
||||||
self.pkicks = 0
|
self.pkicks = 0
|
||||||
self.bans = 0
|
self.bans = 0
|
||||||
self.pbans = 0
|
self.pbans = 0
|
||||||
self.last_seen = 0
|
self.last_seen = None
|
||||||
# private
|
# private
|
||||||
self._last_connect = 0
|
self._last_connect = 0
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,8 @@ def parse_log(log_path, ident_map=None, clients=None, online_dc=True):
|
||||||
logger.debug('No match: "%s"', line)
|
logger.debug('No match: "%s"', line)
|
||||||
continue
|
continue
|
||||||
match = match.groupdict()
|
match = match.groupdict()
|
||||||
stripped_time = datetime.strptime(match['timestamp'],
|
logdatetime = datetime.strptime(match['timestamp'],
|
||||||
log_timestamp_format)
|
log_timestamp_format)
|
||||||
logdatetime = int((stripped_time - datetime(1970, 1, 1))
|
|
||||||
.total_seconds())
|
|
||||||
message = match['message']
|
message = match['message']
|
||||||
if message.startswith('client'):
|
if message.startswith('client'):
|
||||||
nick, clid = re_dis_connect.findall(message)[0]
|
nick, clid = re_dis_connect.findall(message)[0]
|
||||||
|
@ -95,10 +93,7 @@ def parse_log(log_path, ident_map=None, clients=None, online_dc=True):
|
||||||
if online_dc:
|
if online_dc:
|
||||||
for client in clients:
|
for client in clients:
|
||||||
if client.connected:
|
if client.connected:
|
||||||
client.disconnect(
|
client.disconnect(datetime.utcnow())
|
||||||
int((datetime.utcnow() - datetime(1970, 1, 1))
|
|
||||||
.total_seconds())
|
|
||||||
)
|
|
||||||
client.connected += 1
|
client.connected += 1
|
||||||
logger.debug('Finished parsing of %s', log_file.name)
|
logger.debug('Finished parsing of %s', log_file.name)
|
||||||
return clients
|
return clients
|
||||||
|
|
Loading…
Reference in New Issue