From 9c223473c507257d25a77ecea566d830965d7c8f Mon Sep 17 00:00:00 2001 From: Gleb Smirnov Date: Sun, 15 Sep 2024 11:44:14 +0300 Subject: [PATCH] feat: Telegram API ID and hash now can be loaded from environment --- tgpy/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tgpy/main.py b/tgpy/main.py index 85b5b0c..a70ef6d 100644 --- a/tgpy/main.py +++ b/tgpy/main.py @@ -1,7 +1,7 @@ import asyncio import functools import logging -import os.path +import os import platform import subprocess import sys @@ -33,6 +33,14 @@ def wrapper(prompt, password): ) +def get_api_id() -> str | None: + return os.getenv('TGPY_API_ID') or config.get('core.api_id') + + +def get_api_hash() -> str | None: + return os.getenv('TGPY_API_HASH') or config.get('core.api_hash') + + def create_client(): device_model = None if sys.platform == 'linux': @@ -54,8 +62,8 @@ def create_client(): client = TelegramClient( str(SESSION_FILENAME), - config.get('core.api_id'), - config.get('core.api_hash'), + get_api_id(), + get_api_hash(), device_model=device_model, system_version=platform.platform(), lang_code='en', @@ -163,7 +171,7 @@ async def _async_main(): config.load() migrate_config() - if not (config.get('core.api_id') and config.get('core.api_hash')): + if not (get_api_id() and get_api_hash()): await initial_setup() logger.info('Starting TGPy...')