Support configuring SOCKS proxy in the example

This commit is contained in:
zed
2017-06-17 00:17:51 +02:00
committed by Lonami
parent 2b85463ce6
commit 9130a94153
+8 -1
View File
@@ -24,11 +24,18 @@ def load_settings(path='api/settings'):
if __name__ == '__main__':
# Load the settings and initialize the client
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(
session_user_id=str(settings.get('session_name', 'anonymous')),
user_phone=str(settings['user_phone']),
api_id=settings['api_id'],
api_hash=str(settings['api_hash']))
api_hash=str(settings['api_hash']),
**kwargs)
print('Initialization done!')