diff --git a/commandline.py b/commandline.py index 44abd26..e7652c2 100644 --- a/commandline.py +++ b/commandline.py @@ -45,7 +45,7 @@ def handle(): return True else: api_id, api_hash = tttcutils.assert_environment() - client = TelegramClient("tttc", api_id, api_hash) + client = TelegramClient(tttcutils.sessionfile(), api_id, api_hash) debug("Connecting...", file=sys.stderr) client.connect() debug("Connected.", file=sys.stderr) diff --git a/interactive.py b/interactive.py index 7b1b19f..2045c65 100755 --- a/interactive.py +++ b/interactive.py @@ -4,7 +4,7 @@ import os api_id, api_hash = tttcutils.assert_environment() -client = TelegramClient("tttc", api_id, api_hash) +client = TelegramClient(tttcutils.sessionfile(), api_id, api_hash) client.connect() chats = client.get_dialogs() print("client: TelegramClient chats: [Dialog]") diff --git a/tttc.py b/tttc.py index 5449219..125fa30 100755 --- a/tttc.py +++ b/tttc.py @@ -22,7 +22,7 @@ class Display: def __init__(self, loop): self.loop = loop api_id, api_hash = tttcutils.assert_environment() - self.client = TelegramClient("tttc", api_id, api_hash, loop=self.loop) + self.client = TelegramClient(tttcutils.sessionfile(), api_id, api_hash, loop=self.loop) def __enter__(self): diff --git a/tttcutils.py b/tttcutils.py index 7c73a70..2d5524b 100644 --- a/tttcutils.py +++ b/tttcutils.py @@ -17,3 +17,8 @@ def assert_environment(): print("Please consult https://core.telegram.org/api/obtaining_api_id on how to get your own API id and hash.") exit(1) return os.environ["TTTC_API_ID"], os.environ["TTTC_API_HASH"] + +def sessionfile(): + if not os.path.exists(os.path.expanduser("~/.config/tttc")): + os.makedirs(os.path.expanduser("~/.config/tttc/")) + return os.path.expanduser("~/.config/tttc/tttc")