Skip to content

Commit

Permalink
Revert "Add Proxy Support" (PokemonGoF#3304)
Browse files Browse the repository at this point in the history
  • Loading branch information
invisiblek authored and 6iz committed Aug 3, 2016
1 parent aa684ac commit 5e1bec1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 50 deletions.
1 change: 0 additions & 1 deletion config/config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

# Misc
#gmaps-key: # your Google Maps API key
#proxy: # Proxy URL e.g. socks5://127.0.0.1:9050
#webhook: # webhook URL (including http://)

# Webserver settings
Expand Down
14 changes: 5 additions & 9 deletions pogom/pgoapi/pgoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

logger = logging.getLogger(__name__)


class PGoApi:

API_ENTRY = 'https://pgorelease.nianticlabs.com/plfe/rpc'
Expand All @@ -47,7 +46,6 @@ def __init__(self):

self._auth_provider = None
self._api_endpoint = None
self._proxy = None

self._position_lat = 0
self._position_lng = 0
Expand All @@ -60,7 +58,6 @@ def copy(self):
other.log = self.log
other._auth_provider = self._auth_provider
other._api_endpoint = self._api_endpoint
other._proxy = self._proxy
other._position_lat = self._position_lat
other._position_lng = self._position_lng
other._position_alt = self._position_alt
Expand All @@ -76,8 +73,8 @@ def call(self):
return False

player_position = self.get_position()

request = RpcApi(self._auth_provider, self._proxy)
request = RpcApi(self._auth_provider)

if self._api_endpoint:
api_endpoint = self._api_endpoint
Expand Down Expand Up @@ -116,9 +113,6 @@ def set_position(self, lat, lng, alt):
self._position_lng = f2i(lng)
self._position_alt = f2i(alt)

def set_proxy(self, proxy_config):
self._proxy = proxy_config

def __getattr__(self, func):
def function(**kwargs):

Expand All @@ -140,7 +134,8 @@ def function(**kwargs):
return function
else:
raise AttributeError



def login(self, provider, username, password):

if not isinstance(username, basestring) or not isinstance(password, basestring):
Expand Down Expand Up @@ -190,3 +185,4 @@ def login(self, provider, username, password):
self.log.info('Login process completed')

return True

23 changes: 9 additions & 14 deletions pogom/pgoapi/rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,30 @@
"""

import logging
import subprocess
import requesocks
import requests
import subprocess

from exceptions import NotLoggedInException, ServerBusyOrOfflineException

from google.protobuf.message import DecodeError
from protobuf_to_dict import protobuf_to_dict
from utilities import to_camel_case, get_class
from utilities import h2f, to_camel_case, get_class

import protos.RpcEnum_pb2 as RpcEnum
import protos.RpcEnvelope_pb2 as RpcEnvelope

class RpcApi:

def __init__(self, auth_provider, proxy_config=None):
def __init__(self, auth_provider):

self.log = logging.getLogger(__name__)

if proxy_config is None:
self._session = requests.session()
else:
self._session = requesocks.session()
self._session.proxies = proxy_config


self._session = requests.session()
self._session.headers.update({'User-Agent': 'Niantic App'})
self._session.verify = True

self._auth_provider = auth_provider

def get_rpc_id(self):
return 8145806132888207460

Expand All @@ -73,7 +67,7 @@ def _make_rpc(self, endpoint, request_proto_plain):
request_proto_serialized = request_proto_plain.SerializeToString()
try:
http_response = self._session.post(endpoint, data=request_proto_serialized)
except (requests.exceptions.ConnectionError, requesocks.exceptions.ConnectionError):
except requests.exceptions.ConnectionError as e:
raise ServerBusyOrOfflineException

return http_response
Expand Down Expand Up @@ -154,7 +148,8 @@ def _build_sub_requests(self, mainrequest, subrequest_list):
raise Exception('Unknown value in request list')

return mainrequest



def _parse_main_request(self, response_raw, subrequests):
self.log.debug('Parsing main RPC response...')

Expand Down
1 change: 0 additions & 1 deletion pogom/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def search_worker_thread(args, account, search_items_queue, parse_lock):

# Create the API instance this will use
api = PGoApi()
api.set_proxy(args.proxy)

# The forever loop for the thread
while True:
Expand Down
21 changes: 4 additions & 17 deletions pogom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def get_args():
parser.add_argument('-nk', '--no-pokestops',
help='Disables PokeStops from the map (including parsing them into local db)',
action='store_true', default=False)
parser.add_argument('-px', '--proxy', help='Proxy url (e.g. socks5://127.0.0.1:9050)')
parser.add_argument('--db-type', help='Type of database to be used (default: sqlite)',
default='sqlite')
parser.add_argument('--db-name', help='Name of the database to be used')
Expand All @@ -113,12 +112,6 @@ def get_args():

args = parser.parse_args()

if args.proxy is not None:
args.proxy = {
'http': args.proxy,
'https': args.proxy
}

if args.only_server:
if args.location is None:
parser.print_usage()
Expand All @@ -127,16 +120,16 @@ def get_args():
else:
errors = []

if args.username is None:
if (args.username is None):
errors.append('Missing `username` either as -u/--username or in config')

if args.location is None:
if (args.location is None):
errors.append('Missing `location` either as -l/--location or in config')

if args.password is None:
if (args.password is None):
errors.append('Missing `password` either as -p/--password or in config')

if args.step_limit is None:
if (args.step_limit is None):
errors.append('Missing `step_limit` either as -st/--step-limit or in config')

if args.auth_service is None:
Expand Down Expand Up @@ -221,7 +214,6 @@ def insert_mock_data(position):
gym_points=1000
)


def i8ln(word):
if config['LOCALE'] == "en":
return word
Expand All @@ -242,7 +234,6 @@ def i8ln(word):
log.debug('Unable to find translation for "%s" in locale %s!', word, config['LOCALE'])
return word


def get_pokemon_data(pokemon_id):
if not hasattr(get_pokemon_data, 'pokemon'):
file_path = os.path.join(
Expand All @@ -254,20 +245,16 @@ def get_pokemon_data(pokemon_id):
get_pokemon_data.pokemon = json.loads(f.read())
return get_pokemon_data.pokemon[str(pokemon_id)]


def get_pokemon_name(pokemon_id):
return i8ln(get_pokemon_data(pokemon_id)['name'])


def get_pokemon_rarity(pokemon_id):
return i8ln(get_pokemon_data(pokemon_id)['rarity'])


def get_pokemon_types(pokemon_id):
pokemon_types = get_pokemon_data(pokemon_id)['types']
return map(lambda x: {"type": i8ln(x['type']), "color": x['color']}, pokemon_types)


def send_to_webhook(message_type, message):
args = get_args()

Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ PyMySQL==0.7.5
flask-cors==2.1.2
flask-compress==1.3.0
LatLon==1.0.1
stem==1.4.0
requesocks==0.10.8
13 changes: 7 additions & 6 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
args = get_args()

if args.debug:
log.setLevel(logging.DEBUG)
log.setLevel(logging.DEBUG);
else:
log.setLevel(logging.INFO)
log.setLevel(logging.INFO);

# Let's not forget to run Grunt / Only needed when running with webserver
if not args.no_server:
if not os.path.exists(os.path.join(os.path.dirname(__file__), 'static/dist')):
log.critical('Please run "grunt build" before starting the server')
sys.exit()
log.critical('Please run "grunt build" before starting the server');
sys.exit();

# These are very noisey, let's shush them up a bit
logging.getLogger('peewee').setLevel(logging.INFO)
Expand All @@ -55,6 +55,7 @@
logging.getLogger('pgoapi').setLevel(logging.DEBUG)
logging.getLogger('rpc_api').setLevel(logging.DEBUG)


position = get_pos_by_name(args.location)
if not any(position):
log.error('Could not get a position by name, aborting')
Expand Down Expand Up @@ -94,7 +95,7 @@
new_location_queue.put(position)

if not args.only_server:
# Gather the pokemon!
# Gather the pokemons!
if not args.mock:
log.debug('Starting a real search thread')
search_thread = Thread(target=search_overseer_thread, args=(args, new_location_queue, pause_bit))
Expand All @@ -108,7 +109,7 @@
search_thread.start()

if args.cors:
CORS(app)
CORS(app);

app.set_search_control(pause_bit)
app.set_location_queue(new_location_queue)
Expand Down

0 comments on commit 5e1bec1

Please sign in to comment.