Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.2 kB
13
Indexable
Never
def get_client(session, proxy=''):
    ses = f"sessions\\{session}"

    try:
        with open(ses.split('.')[0] + ".json", encoding='utf-8') as f:
            data = json.load(f)
        data = str(data)
        data = eval(data)
        app_id = data["app_id"]
        app_hash = data["app_hash"]
        device = data["device"]
        sdk = data["sdk"]
        app_version = data["app_version"]
        lang_pack = data["lang_pack"]
        system_lang_pack = data["system_lang_pack"]

    except:
        app_id = 2040
        app_hash = 'b18441a1ff607e10a989891a5462e627'
        device = 'Desktop'
        sdk = 'Windows 10'
        app_version = '3.4.3 x64'
        lang_pack = 'en'
        system_lang_pack = 'en-US'



    if proxy == '':
        # return TelegramClient(f"sessions\\{session}", API_ID, API_HASH)
        return TelegramClient(f"sessions\\{session}", api_id=app_id,
                              api_hash=app_hash,device_model=device,
                              system_version=sdk,app_version=app_version,
                              lang_code=lang_pack,
                              system_lang_code=system_lang_pack, connection_retries= 0,
                              auto_reconnect= False)
    else:
        proxy_ip = proxy.split(':')[0]
        proxy_port = proxy.split(':')[1]
        proxy_login = proxy.split(':')[2]
        proxy_password = proxy.split(':')[3].split('\n')[0]

        return TelegramClient(f"sessions\\{session}", api_id= app_id,
                              api_hash= app_hash,device_model= device,
                              system_version= sdk,app_version= app_version,
                              lang_code= lang_pack,
                              system_lang_code= system_lang_pack,
                              proxy=(
                                  socks.HTTP,
                                  proxy_ip,
                                  int(proxy_port),
                                  True,
                                  proxy_login,
                                  proxy_password
                              ),
                              connection_retries= 0, auto_reconnect= False
                              )