diff --git a/configs/config.json.example b/configs/config.json.example index 8020f38a0c..64c559cb7e 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -4,6 +4,8 @@ "password": "YOUR_PASSWORD", "location": "SOME_LOCATION", "gmapkey": "GOOGLE_MAPS_API_KEY", + "proxy_ip": "" , + "proxy_port": 0, "tasks": [ { "type": "HandleSoftBan" diff --git a/pokecli.py b/pokecli.py index e0c982f5e3..0281d938b4 100755 --- a/pokecli.py +++ b/pokecli.py @@ -322,6 +322,26 @@ def init_config(): type=float, default=5.0 ) + add_config( + parser, + load, + short_flag="-prxip", + long_flag="--proxy_ip", + help="Proxy (https and http)", + required=required("proxy_ip"), + type=str, + default=None + ) + add_config( + parser, + load, + short_flag="-prxp", + long_flag="--proxy_port", + help="Proxy port", + required=required("proxy_port"), + type=int, + default=None + ) # Start to parse other attrs config = parser.parse_args() @@ -329,7 +349,9 @@ def init_config(): config.username = raw_input("Username: ") if not config.password and 'password' not in load: config.password = getpass("Password: ") - + + setup_proxy(config) + config.catch = load.get('catch', {}) config.release = load.get('release', {}) config.action_wait_max = load.get('action_wait_max', 4) @@ -401,6 +423,12 @@ def task_configuration_error(flag_name): fix_nested_config(config) return config +def setup_proxy(config): + if config.proxy_ip and len(config.proxy_ip)>0 and config.proxy_ip.count('.') == 3 and all(0<=int(num)<256 for num in config.proxy_ip.rstrip().split('.')): + if config.proxy_port and int(config.proxy_port )<65536 and int(config.proxy_port )>1: + os.environ['http_proxy']="http://"+config.proxy_ip+":"+str(config.proxy_port)+"/" + os.environ['https_proxy']="http://"+config.proxy_ip+":"+str(config.proxy_port)+"/" + def add_config(parser, json_config, short_flag=None, long_flag=None, **kwargs): if not long_flag: raise Exception('add_config calls requires long_flag parameter!')