Skip to content

Commit

Permalink
Supporting sending requests through an HTTP proxy (#2358)
Browse files Browse the repository at this point in the history
* Added proxy support

Added proxy support from config.json and command line. with parameters:

-prxip | --proxy_ip  or proxy_ip from config.json for ipv4 format as string "aaa.bbb.ccc.ddd"

-prxp| --proxy_port or proxy_por from config.json as int from 1 to 65536.

* Added proxy support

Added two additional parameters (proxy_ip and proxy_port) to add support for proxy.

proxy_ip must be as string of ipv4 format: "aaa.bbb.ccc.ddd" , proxy_port must be a int from 1 to 65536, if proxy_ip is null or set to "" and proxy port is null or set to 0 proxy will be ignored and not used.

* Moved proxy function to a method.

Moved proxy function to a method.

* Changed the name of method

Changed from set_proxy_if_exists to setup_proxy
  • Loading branch information
alecuba16 authored and elicwhite committed Aug 2, 2016
1 parent ea42eac commit fbda65e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"proxy_ip": "" ,
"proxy_port": 0,
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
30 changes: 29 additions & 1 deletion pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,36 @@ 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()
if not config.username and 'username' not in load:
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)
Expand Down Expand Up @@ -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!')
Expand Down

0 comments on commit fbda65e

Please sign in to comment.