From 8d733933c877cab1f7edbd6c24015a0a4d3cdd1f Mon Sep 17 00:00:00 2001 From: Tim <53166177+TimMcCool@users.noreply.github.com> Date: Sun, 18 Jun 2023 18:19:19 +0200 Subject: [PATCH] v1.2.6 Signed-off-by: Tim <53166177+TimMcCool@users.noreply.github.com> --- scratchattach/_cloud.py | 7 ++++++- scratchattach/_cloud_requests.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scratchattach/_cloud.py b/scratchattach/_cloud.py index 3c93d4df..88878650 100644 --- a/scratchattach/_cloud.py +++ b/scratchattach/_cloud.py @@ -17,7 +17,8 @@ def __init__(self, *, project_id, username="python", session_id=None, cloud_host self.project_id = int(project_id) except ValueError: #non-numeric project id (possible on turbowarp's cloud server) self.project_id = str(project_id) - self._ratelimited_until = 0#deals with the 0.1 second rate limit for cloud variable sets + self._ratelimited_until = 0 #deals with the 0.1 second rate limit for cloud variable sets + self._connect_timestamp = 0 #timestamp of when the cloud connection was opened self.websocket = websocket.WebSocket() self._no_reconnect = False self._connect(cloud_host=cloud_host) @@ -86,6 +87,7 @@ def _connect(self, *, cloud_host): ) except Exception: raise(_exceptions.ConnectionError) + self._connect_timestamp = time.time() def set_var(self, variable, value): variable = variable.replace("☁ ", "") @@ -142,6 +144,7 @@ def _connect(self, *, cloud_host): ) except Exception: raise(_exceptions.ConnectionError) + self._connect_timestamp = time.time() def get_cloud(self, variable): try: @@ -318,6 +321,8 @@ def _update(self): while True: try: data = self.connection.websocket.recv().split('\n') + if len(data) > 1 and time.time() < self.connection._connect_timestamp + 0.5: + continue result = [] for i in data: try: diff --git a/scratchattach/_cloud_requests.py b/scratchattach/_cloud_requests.py index cf7289ec..1c515f1f 100644 --- a/scratchattach/_cloud_requests.py +++ b/scratchattach/_cloud_requests.py @@ -179,6 +179,18 @@ def get_timestamp(self): return self.last_timestamp + def get_exact_timestamp(self): + + logs = _cloud.get_cloud_logs(self.project_id, + filter_by_var_named="TO_HOST") + activity = list( + filter(lambda x: "." + self.last_request_id in x["value"], + logs)) + if len(activity) > 0: + return activity[0]["timestamp"] + else: + return None + def _respond(self, request_id, response, limit, *, validation=2222): if self.idle_since + 8 < time.time() or self.force_reconnect: