From fc4a1225160d2c969550576159a24c9f7d3639ec Mon Sep 17 00:00:00 2001 From: jantuomi Date: Wed, 20 Jul 2016 14:42:40 +0300 Subject: Fix timestamp parsing --- project/botmanager.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'project/botmanager.py') diff --git a/project/botmanager.py b/project/botmanager.py index 805f20c..7fa15a1 100644 --- a/project/botmanager.py +++ b/project/botmanager.py @@ -5,9 +5,8 @@ import random import sys import time import traceback - import telepot - +from dateutil.parser import parse from project.jsonfactory import JSONFactory from project.shoutboxapicommunicator import ShoutboxCommunicator from project.telegramapicommunicator import TelegramCommunicator @@ -67,8 +66,16 @@ class BotManager(object): # if the message is older than 2 * call interval, # pop it from the buffer because there is no way # it can be a duplicate anymore - timestamp = round(float(self.last_message_timestamps[msg_id])) - if not round(time.time()) - timestamp < 2 * ShoutboxCommunicator.interval: + str_stamp = self.last_message_timestamps[msg_id] + try: + timestamp = round(float(str_stamp)) + except ValueError: + timestamp_st = parse(timestamp) + timestamp = int(time.mktime(timestamp_st.timetuple())) + + print("Timestamp: {}, now: {}".format(round(time.time()), timestamp)) + + if not abs(round(time.time()) - timestamp) < 2 * ShoutboxCommunicator.interval: new_message_dict[msg_id] = self.last_message_timestamps[msg_id] else: logging.info("Popped message from buffer.") -- cgit v1.3