forked from alexander-akhmetov/python-telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
42 lines (37 loc) · 1.65 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import logging
import argparse
def setup_logging(level=logging.INFO):
root = logging.getLogger()
root.setLevel(level)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(name)s: %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)
def add_api_args(parser: argparse.ArgumentParser):
parser.add_argument('api_id', help='API id') # https://my.telegram.org/apps
parser.add_argument('api_hash', help='API hash')
parser.add_argument('phone', help='Phone')
def add_proxy_args(parser: argparse.ArgumentParser):
parser.add_argument('--proxy_server', help='Proxy server', default='', required=False)
parser.add_argument('--proxy_port', help='Proxy port', default='', required=False)
parser.add_argument('--proxy_type', help='Proxy type (socks5, http, mtproxy)', default='', required=False)
parser.add_argument('--proxy_username', help='Proxy user name', default='', required=False)
parser.add_argument('--proxy_password', help='Proxy password', default='', required=False)
parser.add_argument('--proxy_secret', help='Proxy secret (mtproxy)', default='', required=False)
def parse_proxy_type(args):
obj_type = {
'socks5': 'proxyTypeSocks5',
'http': 'proxyTypeHttp',
'mtproxy': 'proxyTypeMtproto',
}
if args.proxy_type not in obj_type:
return None
obj = {'@type': obj_type[args.proxy_type]}
if args.proxy_type in ['http', 'socks5']:
obj['username'] = args.proxy_username
obj['password'] = args.proxy_password
else:
obj['secret'] = args.secret
return obj