Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
update: KeyboardInterapt exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaDove committed Jun 24, 2021
1 parent ba3d2f5 commit def0cb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
long_description = fh.read()

setuptools.setup(
name="teleout",
version="1.0.8",
name="teleout",
version="1.0.9",
author="Peter Ibragimov",
author_email="peter.ibragimov@gmail.com",
description="Terminal utility, for sending data directly to telegram users via pipes, files(pure and ziped) or just text.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/TeaDove/teleout",
download_url='https://github.com/TeaDove/teleout/archive/v1.0.8.tar.gz',
download_url='https://github.com/TeaDove/teleout/archive/v1.0.9.tar.gz',
licence='gpl-3.0',
keywords = ['TELEGRAM', 'PIPE', 'UTILITY'],
keywords = ['TELEGRAM', 'PIPE', 'UTILITY'],
packages=setuptools.find_packages(),
include_package_data=True,
classifiers=[
Expand Down
21 changes: 12 additions & 9 deletions teleout/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import html

from tqdm import tqdm
from pyrogram.session import Session
from pyrogram.session import Session
from pyrogram import Client, filters, types, session

BASE_FOLDER = Path(__file__).parent.absolute()
Expand All @@ -25,12 +25,12 @@ def __init__(self, folder_name=BASE_FOLDER / Path("secret_data")):
self.__config.read(folder_name / "config.ini")

self.app = Client(session_name=str(self.folder_name / "my_account"), api_id=self.__config['credentials']['pyrogram_api_id'],
api_hash=self.__config['credentials']['pyrogram_api_hash'], parse_mode="html", no_updates=True, hide_password=True)
api_hash=self.__config['credentials']['pyrogram_api_hash'], parse_mode="html", no_updates=True, hide_password=True)

def __enter__(self):
self.app.start()
return self.app

def __exit__(self, type, value, traceback):
self.app.stop()

Expand Down Expand Up @@ -65,9 +65,9 @@ def send_data(data: str, user:str = "me", data_type:str = "text", caption: str =
else:
app.send_message(user, data, parse_mode = parse_mode)
elif data_type == "file":
with tqdm(total=100) as pbar:
with tqdm(total=100) as pbar:
def progress(current, total):
pbar.update(round(current * 100 / total, 4) - pbar.n)
pbar.update(round(current * 100 / total, 4) - pbar.n)
if caption is not None:
app.send_document(user, data, caption=caption[:1024], progress=progress)
else:
Expand All @@ -89,15 +89,15 @@ def main():
parser.add_argument('--html', action='store_true', help='parse as html and apply <b>, <i> etc. tags')
parser.add_argument('--ansi-colors', action='store_true', help="don't remove ANSI escape codes from piped strings")
args = parser.parse_args()

# Pipe handling
pipe = None
if select.select([sys.stdin, ], [], [], 0.0)[0]:
pipe = sys.stdin.read()
if not args.ansi_colors:
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
pipe = ansi_escape.sub('', pipe)

if args.html:
parse_mode = "html"
else:
Expand Down Expand Up @@ -137,7 +137,7 @@ def main():
elif file.is_dir():
delete_file = True
file = zipdir(file)

# New user handling
if args.new_user:
session_file = BASE_FOLDER / Path("secret_data/my_account.session")
Expand All @@ -163,4 +163,7 @@ def main():
file.unlink()

if __name__ == "__main__":
main()
try:
main()
except KeyboardInterrupt:
sys.exit("\nCancelling...")

0 comments on commit def0cb3

Please sign in to comment.