Skip to content

Commit

Permalink
Use pogeo's Location type
Browse files Browse the repository at this point in the history
  • Loading branch information
Noctem committed May 30, 2017
1 parent 18ad412 commit 12ed079
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 33 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Documentation is available at the [pgoapi wiki](https://wiki.pogodev.org).
* Python ≥3.5
* aiohttp
* protobuf (≥3)
* pycrypt
* cyrandom
* [pycrypt](https://github.com/Noctem/pycrypt)
* [cyrandom](https://github.com/Noctem/cyrandom)
* [pogeo](https://github.com/Noctem/pogeo)

##### Optional Packages
* *gpsoauth*: required for Google accounts
Expand Down
2 changes: 1 addition & 1 deletion aiopogo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = 'aiopogo'
__version__ = '2.0.1'
__version__ = '2.1.0b0'
__author__ = 'David Christenson'
__license__ = 'MIT License'
__copyright__ = 'Copyright (c) 2017 David Christenson <https://github.com/Noctem>'
Expand Down
39 changes: 12 additions & 27 deletions aiopogo/pgoapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from logging import getLogger

from yarl import URL
from aiohttp import BasicAuth
from pogeo import Location
from yarl import URL
try:
from aiosocks import Socks4Auth, Socks5Auth
except ImportError:
Expand All @@ -24,16 +25,12 @@ class PGoApi:
log = getLogger(__name__)
log.info('%s v%s', __title__, __version__)

def __init__(self, lat=None, lon=None, alt=None, proxy=None, device_info=None):
def __init__(self, proxy=None, device_info=None):
self.auth_provider = None
self.state = RpcState()

self._api_endpoint = 'https://pgorelease.nianticlabs.com/plfe/rpc'

self.latitude = lat
self.longitude = lon
self.altitude = alt

self.proxy_auth = None
self.proxy = proxy
self.device_info = device_info
Expand All @@ -57,34 +54,23 @@ async def set_authentication(self, provider='ptc', username=None, password=None,

await self.auth_provider.user_login(username, password)

def set_position(self, lat, lon, alt=None):
self.log.debug('Set Position - Lat: %s Lon: %s Alt: %s', lat, lon, alt)
self.latitude = lat
self.longitude = lon
self.altitude = alt
def set_position(self, lat, lon, alt=0.0):
"""Deprecated position setter, setting directly is recommended"""
self.position = Location(lat, lon)
self.position[2] = alt

def create_request(self):
return PGoApiRequest(self)

@staticmethod
def activate_hash_server(hash_token, conn_limit=300):
HashServer.set_token(hash_token)
HashServer.activate_session(conn_limit)

@property
def position(self):
return self.latitude, self.longitude, self.altitude

@property
def api_endpoint(self):
return self._api_endpoint

@api_endpoint.setter
def api_endpoint(self, api_url):
if api_url.startswith("https"):
self._api_endpoint = URL(api_url)
else:
self._api_endpoint = URL('https://' + api_url + '/rpc')
self._api_endpoint = (URL(api_url)
if api_url.startswith("https")
else URL('https://' + api_url + '/rpc'))

@property
def proxy(self):
Expand Down Expand Up @@ -136,10 +122,9 @@ def __init__(self, parent):
async def call(self):
parent = self.__parent__
auth_provider = parent.auth_provider
position = parent.position
try:
assert position[0] is not None and position[1] is not None
except AssertionError:
position = parent.position
except AttributeError:
raise NoPlayerPositionSetException('No position set.')

request = RpcApi(auth_provider, parent.state)
Expand Down
2 changes: 1 addition & 1 deletion aiopogo/rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async def _build_main_request(self, subrequests, player_position, device_info=No
loc.latitude = request.latitude
loc.longitude = request.longitude

loc.altitude = altitude or uniform(150, 250)
loc.altitude = altitude or uniform(390.0, 490.0)

if random() > .85:
# no reading for roughly 1 in 7 updates
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ aiohttp>=2.0.7,<2.2
pycrypt>=0.7.0
cyrandom>=0.1.2
yarl>=0.10.0
pogeo>=0.4b0
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
author='David Christenson',
author_email='mail@noctem.xyz',
description='Asynchronous Pokemon API lib',
version='2.0.1',
version='2.1.0b0',
url='https://github.com/Noctem/aiopogo',
packages=find_packages(),
install_requires=[
'protobuf>=3.0.0',
'aiohttp>=2.0.7,<2.2',
'pycrypt>=0.7.0',
'cyrandom>=0.1.2'],
'cyrandom>=0.1.2',
'pogeo>=0.4b0'],
extras_require={
'performance': ['ujson>=1.3.5', 'cchardet>=2.1.0', 'aiodns>=1.1.1'],
'socks': ['aiosocks>=0.2.2'],
Expand Down

0 comments on commit 12ed079

Please sign in to comment.