Support configuring SOCKS proxy in the example

This commit is contained in:
zed 2017-06-17 01:17:51 +03:00 committed by Lonami
parent 2b85463ce6
commit 9130a94153

View File

@ -24,11 +24,18 @@ def load_settings(path='api/settings'):
if __name__ == '__main__': if __name__ == '__main__':
# Load the settings and initialize the client # Load the settings and initialize the client
settings = load_settings() settings = load_settings()
kwargs = {}
if settings.get('socks_proxy'):
import socks # $ pip install pysocks
host, port = settings['socks_proxy'].split(':')
kwargs = dict(proxy=(socks.SOCKS5, host, int(port)))
client = InteractiveTelegramClient( client = InteractiveTelegramClient(
session_user_id=str(settings.get('session_name', 'anonymous')), session_user_id=str(settings.get('session_name', 'anonymous')),
user_phone=str(settings['user_phone']), user_phone=str(settings['user_phone']),
api_id=settings['api_id'], api_id=settings['api_id'],
api_hash=str(settings['api_hash'])) api_hash=str(settings['api_hash']),
**kwargs)
print('Initialization done!') print('Initialization done!')