From 8e4e30e53c62859215c9466c9ec7825c70856cc0 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Sat, 23 Jan 2021 21:08:47 +0100 Subject: [PATCH] use also servetime as timestamp in isoformat --- .../classes/WebSocketsPool.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 950dffb..baf7119 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -4,6 +4,7 @@ import time import json import random +from datetime import fromtimestamp from dateutil import parser from TwitchChannelPointsMiner.classes.EventPrediction import EventPrediction @@ -124,7 +125,19 @@ class WebSocketsPool: message_type = message["type"] message_data = message["data"] if "data" in message else None - message_timestamp = None if message_data is None else message_data["timestamp"] + message_timestamp = ( + None + if message_data is None + else ( + message_data["timestamp"] + if "timestamp" in message_data + else ( + fromtimestamp(message_data["server_time"]).isoformat() + "Z" + if "server_time" in message_data + else fromtimestamp(time.time()).isoformat() + "Z" + ) + ) + ) channel_id = ( None @@ -147,7 +160,8 @@ class WebSocketsPool: # If we have more than one PubSub connection, messages may be duplicated # Check the concatenation between message_type and channel_id if ( - ws.last_message_timestamp == message_timestamp + ws.last_message_type_channel != ws.last_message_timestamp + and ws.last_message_timestamp == message_timestamp and ws.last_message_type_channel == f"{message_type}.{channel_id}" ): return