Skip to content

Commit

Permalink
Performance enhancements
Browse files Browse the repository at this point in the history
Don't convert protobuf objects to dicts, add request methods with
arguments as a tuple instead of a dict, simplify redirection exception,
remove some unnecessary labels that are only used once, use protobuf
extend method instead of appending in loops, store a global reference
to imported global modules and use that instead of running
import_module every time.
  • Loading branch information
Noctem committed May 19, 2017
1 parent f46fa8e commit cdf8369
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 169 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
git:
depth: 5
language: python
python:
- '3.5'
- '3.6'
matrix:
include:
- python: '3.5'
- python: '3.6'
- python: '3.7-dev'
allow_failures:
- python: 3.7-dev
install:
- pip install -r requirements.txt
- pip install -U -r requirements.txt
- python setup.py install
script:
- python -c 'from aiopogo import auth_google, auth_ptc, auth, connector, exceptions, hash_server, pgoapi, rpc_api, session, utilities'
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
[![Build Status](https://travis-ci.org/Noctem/aiopogo.svg)](https://travis-ci.org/Noctem/aiopogo)

# aiopogo - a Pokémon API in Python
It allows automatic parsing of requests/responses by finding the correct protobuf objects over a naming convention and will return the response in a parsed Python dictionary format.
It allows automatic parsing of requests/responses by finding the correct protobuf objects over a naming convention and will return the response in a dictionary of protobuf messages.

* This is unofficial, use at your own risk!
* No bot/farming code included!

## Feature Support
* Python 3
* Google/PTC auth
* Address parsing for GPS coordinates
* Chaining of RPC calls
* Re-auth if ticket expired
* Check for server side-throttling
* Asynchronous IO
* Advanced logging/debugging
* Uses [POGOProtos](https://github.com/Noctem/POGOProtos)
Expand All @@ -33,8 +31,6 @@ Documentation is available at the [pgoapi wiki](https://wiki.pogodev.org).
Contributions are very welcome, feel free to submit a pull request.

## Credits
[Mila432](https://github.com/Mila432/Pokemon_Go_API) for the login secrets
[elliottcarlson](https://github.com/elliottcarlson) for the Google Auth PR
[AeonLucid](https://github.com/AeonLucid/POGOProtos) for improved protos
[AeonLucid](https://github.com/AeonLucid/POGOProtos) for improved protos
[tejado](https://github.com/tejado/pgoapi) for the original project
[pogodev](https://github.com/pogodevorg/pgoapi) for keeping it alive
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__ = '1.9.1'
__version__ = '2.0'
__author__ = 'David Christenson'
__license__ = 'MIT License'
__copyright__ = 'Copyright (c) 2017 David Christenson <https://github.com/Noctem>'
Expand Down
6 changes: 3 additions & 3 deletions aiopogo/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def has_ticket(self):
return self._ticket_expire and self._ticket_start and self._ticket_end

def set_ticket(self, auth_ticket):
timestamp = auth_ticket['expire_timestamp_ms']
timestamp = auth_ticket.expire_timestamp_ms
if timestamp > self._ticket_expire:
self._ticket_expire = timestamp
self._ticket_start = auth_ticket['start']
self._ticket_end = auth_ticket['end']
self._ticket_start = auth_ticket.start
self._ticket_end = auth_ticket.end

def is_new_ticket(self, new_ticket_time_ms):
return new_ticket_time_ms > self._ticket_expire
Expand Down
9 changes: 2 additions & 7 deletions aiopogo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ class UnexpectedHashResponseException(UnexpectedResponseException, HashServerExc

class ServerApiEndpointRedirectException(AiopogoError):
"""Raised when the API redirects you to another endpoint"""
def __init__(self):
self._api_endpoint = None
def __init__(self, endpoint):
self.endpoint = endpoint

def get_redirected_endpoint(self):
return self._api_endpoint

def set_redirected_endpoint(self, api_endpoint):
self._api_endpoint = api_endpoint
4 changes: 2 additions & 2 deletions aiopogo/pgoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def call(self):
await auth_provider.get_access_token(force_refresh=True)
except ServerApiEndpointRedirectException as e:
self.log.debug('API endpoint redirect... re-executing call')
parent.api_endpoint = e.get_redirected_endpoint()
parent.api_endpoint = e.endpoint

# cleanup after call execution
self._req_method_list = []
Expand All @@ -158,7 +158,7 @@ def function(**kwargs):

try:
if kwargs:
self._req_method_list.append({RequestType.Value(func): kwargs})
self._req_method_list.append((RequestType.Value(func), kwargs))
self.log.debug("Arguments of '%s': \n\r%s", func, kwargs)
else:
self._req_method_list.append(RequestType.Value(func))
Expand Down
Loading

0 comments on commit cdf8369

Please sign in to comment.