aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjantuomi <jans.tuomi@gmail.com>2016-07-20 14:42:40 +0300
committerjantuomi <jans.tuomi@gmail.com>2016-07-20 14:43:36 +0300
commitfc4a1225160d2c969550576159a24c9f7d3639ec (patch)
tree8bf113613c5bf436d28fa33eb29b61dca95041b5
parent23f39b599964513cb560617533313bc31d4aad86 (diff)
Fix timestamp parsing
-rw-r--r--project/botmanager.py15
1 files changed, 11 insertions, 4 deletions
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.")