From 1a5f65bdc2e485afe5e67729a340a4d486f48fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 10 Dec 2014 21:41:22 +0100 Subject: [PATCH] Try to fix UTC problem --- default_conf.py | 3 +-- iwla.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/default_conf.py b/default_conf.py index 18cc103..0d1df53 100644 --- a/default_conf.py +++ b/default_conf.py @@ -23,8 +23,7 @@ log_format = '$server_name:$server_port $remote_addr - $remote_user [$time_local '"$http_referer" "$http_user_agent"' # Time format used in log format -# TOFIX UTC -time_format = '%d/%b/%Y:%H:%M:%S +0100' +time_format = '%d/%b/%Y:%H:%M:%S %z' # Hooks that are loaded at runtime (only set names without path and extensions) pre_analysis_hooks = [] diff --git a/iwla.py b/iwla.py index d24dacc..44ea4b4 100755 --- a/iwla.py +++ b/iwla.py @@ -310,7 +310,22 @@ class IWLA(object): return True def _decodeTime(self, hit): - hit['time_decoded'] = time.strptime(hit['time_local'], conf.time_format) + try: + hit['time_decoded'] = time.strptime(hit['time_local'], conf.time_format) + except ValueError, e: + if sys.version_info < (3, 2): + # Try without UTC value at the end (%z not recognized) + gmt_offset_str = hit['time_local'][-5:] + gmt_offset_hours = int(gmt_offset_str[1:3])*60*60 + gmt_offset_minutes = int(gmt_offset_str[3:5])*60 + gmt_offset = gmt_offset_hours + gmt_offset_minutes + hit['time_decoded'] = time.strptime(hit['time_local'][:-6], conf.time_format[:-3]) + if gmt_offset_str[0] == '+': + hit['time_decoded'] = time.localtime(time.mktime(hit['time_decoded'])+gmt_offset) + else: + hit['time_decoded'] = time.localtime(time.mktime(hit['time_decoded'])-gmt_offset) + else: + raise e return hit['time_decoded'] def getDisplayIndex(self): @@ -583,7 +598,7 @@ class IWLA(object): print '==> Load previous database' self.meta_infos = self._deserialize(conf.META_PATH) or self._clearMeta() - if 'last_time' in self.meta_infos.keys(): + if self.meta_infos['last_time']: self.current_analysis = self._deserialize(self.getDBFilename(self.meta_infos['last_time'])) or self._clearVisits() else: self._clearVisits()