Skip to content

Commit

Permalink
warn once on error
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Apr 4, 2022
1 parent a1d4401 commit 7994aa8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tqdm/contrib/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, token, channel_id):
self.message = client.api.channels_messages_create(channel_id, self.text)
except Exception as e:
tqdm_auto.write(str(e))
self.message = None

def write(self, s):
"""Replaces internal `message`'s text with `s`."""
Expand All @@ -47,9 +48,12 @@ def write(self, s):
s = s.replace('\r', '').strip()
if s == self.text:
return # skip duplicate message
message = self.message
if message is None:
return
self.text = s
try:
future = self.submit(self.message.edit, '`' + s + '`')
future = self.submit(message.edit, '`' + s + '`')
except Exception as e:
tqdm_auto.write(str(e))
else:
Expand Down
8 changes: 6 additions & 2 deletions tqdm/contrib/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, token, channel):
self.message = self.client.chat_postMessage(channel=channel, text=self.text)
except Exception as e:
tqdm_auto.write(str(e))
self.message = None

def write(self, s):
"""Replaces internal `message`'s text with `s`."""
Expand All @@ -45,10 +46,13 @@ def write(self, s):
s = s.replace('\r', '').strip()
if s == self.text:
return # skip duplicate message
message = self.message
if message is None:
return
self.text = s
try:
future = self.submit(self.client.chat_update, channel=self.message["channel"],
ts=self.message["ts"], text='`' + s + '`')
future = self.submit(self.client.chat_update, channel=message["channel"],
ts=message["ts"], text='`' + s + '`')
except Exception as e:
tqdm_auto.write(str(e))
else:
Expand Down

0 comments on commit 7994aa8

Please sign in to comment.