Skip to content

Commit

Permalink
feat: Telegram API ID and hash now can be loaded from environment
Browse files Browse the repository at this point in the history
  • Loading branch information
liferooter authored and vanutp committed Sep 15, 2024
1 parent 323d431 commit 9c22347
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tgpy/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import functools
import logging
import os.path
import os
import platform
import subprocess
import sys
Expand Down Expand Up @@ -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':
Expand All @@ -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',
Expand Down Expand Up @@ -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...')
Expand Down

0 comments on commit 9c22347

Please sign in to comment.