Merge pull request #1189 from raulsaavedr/raulsaavedr-tqdm

This commit is contained in:
Casper da Costa-Luis 2021-06-30 17:57:36 +01:00 committed by GitHub
commit 4735e81cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -62,6 +62,17 @@ class TelegramIO(MonoWorker):
else:
return future
def delete(self):
"""Deletes internal `message_id`."""
try:
future = self.submit(
self.session.post, self.API + '%s/deleteMessage' % self.token,
data={'chat_id': self.chat_id, 'message_id': self.message_id})
except Exception as e:
tqdm_auto.write(str(e))
else:
return future
class tqdm_telegram(tqdm_auto):
"""
@ -112,6 +123,13 @@ class tqdm_telegram(tqdm_auto):
if not self.disable:
self.tgio.write("")
def close(self):
if self.disable:
return
super(tqdm_telegram, self).close()
if not (self.leave or (self.leave is None and self.pos == 0)):
self.tgio.delete()
def ttgrange(*args, **kwargs):
"""

View File

@ -113,10 +113,10 @@ class tqdm_rich(std_tqdm): # pragma: no cover
self._prog.__enter__()
self._task_id = self._prog.add_task(self.desc or "", **d)
def close(self, *args, **kwargs):
def close(self):
if self.disable:
return
super(tqdm_rich, self).close(*args, **kwargs)
super(tqdm_rich, self).close()
self._prog.__exit__(None, None, None)
def clear(self, *_, **__):