Skip to content

Commit 8d73393

Browse files
authored
v1.2.6
Signed-off-by: Tim <[email protected]>
1 parent ce4eca3 commit 8d73393

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

scratchattach/_cloud.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def __init__(self, *, project_id, username="python", session_id=None, cloud_host
1717
self.project_id = int(project_id)
1818
except ValueError: #non-numeric project id (possible on turbowarp's cloud server)
1919
self.project_id = str(project_id)
20-
self._ratelimited_until = 0#deals with the 0.1 second rate limit for cloud variable sets
20+
self._ratelimited_until = 0 #deals with the 0.1 second rate limit for cloud variable sets
21+
self._connect_timestamp = 0 #timestamp of when the cloud connection was opened
2122
self.websocket = websocket.WebSocket()
2223
self._no_reconnect = False
2324
self._connect(cloud_host=cloud_host)
@@ -86,6 +87,7 @@ def _connect(self, *, cloud_host):
8687
)
8788
except Exception:
8889
raise(_exceptions.ConnectionError)
90+
self._connect_timestamp = time.time()
8991

9092
def set_var(self, variable, value):
9193
variable = variable.replace("☁ ", "")
@@ -142,6 +144,7 @@ def _connect(self, *, cloud_host):
142144
)
143145
except Exception:
144146
raise(_exceptions.ConnectionError)
147+
self._connect_timestamp = time.time()
145148

146149
def get_cloud(self, variable):
147150
try:
@@ -318,6 +321,8 @@ def _update(self):
318321
while True:
319322
try:
320323
data = self.connection.websocket.recv().split('\n')
324+
if len(data) > 1 and time.time() < self.connection._connect_timestamp + 0.5:
325+
continue
321326
result = []
322327
for i in data:
323328
try:

scratchattach/_cloud_requests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ def get_timestamp(self):
179179

180180
return self.last_timestamp
181181

182+
def get_exact_timestamp(self):
183+
184+
logs = _cloud.get_cloud_logs(self.project_id,
185+
filter_by_var_named="TO_HOST")
186+
activity = list(
187+
filter(lambda x: "." + self.last_request_id in x["value"],
188+
logs))
189+
if len(activity) > 0:
190+
return activity[0]["timestamp"]
191+
else:
192+
return None
193+
182194
def _respond(self, request_id, response, limit, *, validation=2222):
183195

184196
if self.idle_since + 8 < time.time() or self.force_reconnect:

0 commit comments

Comments
 (0)