Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
julienlavergne committed Aug 8, 2016
2 parents 4b0faaa + 4b16e9d commit e8fd901
Show file tree
Hide file tree
Showing 17 changed files with 548 additions and 493 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Please check configuration at http://jsonlint.com/ before posting an issue.

### Expected Behavior


Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* matheussampaio
* Abraxas000
* lucasfevi
* pokepal
* Moonlight-Angel
* mjmadsen
* nikofil
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

# PokemonGo-Bot
# PokemonGo-Bot (Working)
PokemonGo bot is a project created by the [PokemonGoF](https://github.com/PokemonGoF) team.
The project is currently setup in two main branches. `dev` and `master`.


## Where to get the dll/so ?
You need grab them from internet.
## Please submit PR to [Dev branch](https://github.com/PokemonGoF/PokemonGo-Bot/tree/dev)

We use [Slack](https://slack.com) as a web chat. [Click here to join the chat!](https://pokemongo-bot.herokuapp.com)
You can count on the community in #help channel.

## Table of Contents
- [Features](#features)
Expand Down Expand Up @@ -64,10 +63,11 @@ To ensure that all updates are documented - [@eggins](https://github.com/eggins)

## Credits
- [tejado](https://github.com/tejado) many thanks for the API
- [U6 Group](http://pgoapi.com) for the U6
- [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
- [AHAAAAAAA](https://github.com/AHAAAAAAA/PokemonGo-Map) for parts of the s2sphere stuff


[![Analytics](https://ga-beacon.appspot.com/UA-81468120-1/welcome-page-dev)](https://github.com/igrigorik/ga-beacon)
[![Analytics](https://ga-beacon.appspot.com/UA-81468120-1/welcome-page-master)](https://github.com/igrigorik/ga-beacon)
1 change: 1 addition & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"password": "YOUR_PASSWORD",
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"libencrypt_location": "",
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
File renamed without changes.
28 changes: 23 additions & 5 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
from pokemongo_bot.health_record import BotEvent
from pokemongo_bot.plugin_loader import PluginLoader

try:
from demjson import jsonlint
except ImportError:
# Run `pip install -r requirements.txt` to fix this
jsonlint = None

if sys.version_info >= (2, 7, 9):
ssl._create_default_https_context = ssl._create_unverified_context

Expand Down Expand Up @@ -104,7 +110,7 @@ def main():
'api_error',
sender=bot,
level='info',
formatted='Log logged in, reconnecting in {:s}'.format(wait_time)
formatted='Log logged in, reconnecting in {:d}'.format(wait_time)
)
time.sleep(wait_time)
except ServerBusyOrOfflineException:
Expand Down Expand Up @@ -162,16 +168,28 @@ def init_config():
# If config file exists, load variables from json
load = {}

def _json_loader(filename):
try:
with open(filename, 'rb') as data:
load.update(json.load(data))
except ValueError:
if jsonlint:
with open(filename, 'rb') as data:
lint = jsonlint()
rc = lint.main(['-v', filename])

logger.critical('Error with configuration file')
sys.exit(-1)

# Select a config file code
parser.add_argument("-cf", "--config", help="Config File to use")
config_arg = parser.parse_known_args() and parser.parse_known_args()[0].config or None

if config_arg and os.path.isfile(config_arg):
with open(config_arg) as data:
load.update(json.load(data))
_json_loader(config_arg)
elif os.path.isfile(config_file):
logger.info('No config argument specified, checking for /configs/config.json')
with open(config_file) as data:
load.update(json.load(data))
_json_loader(config_file)
else:
logger.info('Error: No /configs/config.json or specified config')

Expand Down
26 changes: 23 additions & 3 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import re
import sys
import time
import Queue
import threading

from geopy.geocoders import GoogleV3
from pgoapi import PGoApi
Expand Down Expand Up @@ -69,6 +71,11 @@ def __init__(self, config):
# Make our own copy of the workers for this instance
self.workers = []

# Theading setup for file writing
self.web_update_queue = Queue.Queue(maxsize=1)
self.web_update_thread = threading.Thread(target=self.update_web_location_worker)
self.web_update_thread.start()

def start(self):
self._setup_event_system()
self._setup_logging()
Expand Down Expand Up @@ -225,10 +232,12 @@ def _register_events(self):
'iv_display',
)
)
self.event_manager.register_event('no_pokeballs')
self.event_manager.register_event(
'pokemon_catch_rate',
parameters=(
'catch_rate',
'ball_name',
'berry_name',
'berry_count'
)
Expand All @@ -237,25 +246,28 @@ def _register_events(self):
'threw_berry',
parameters=(
'berry_name',
'ball_name',
'new_catch_rate'
)
)
self.event_manager.register_event(
'threw_pokeball',
parameters=(
'pokeball',
'ball_name',
'success_percentage',
'count_left'
)
)
self.event_manager.register_event(
'pokemon_fled',
'pokemon_capture_failed',
parameters=('pokemon',)
)
self.event_manager.register_event(
'pokemon_vanished',
parameters=('pokemon',)
)
self.event_manager.register_event('pokemon_not_in_range')
self.event_manager.register_event('pokemon_inventory_full')
self.event_manager.register_event(
'pokemon_caught',
parameters=(
Expand Down Expand Up @@ -976,7 +988,15 @@ def heartbeat(self):
request.get_player()
request.check_awarded_badges()
request.call()
self.update_web_location() # updates every tick
try:
self.web_update_queue.put_nowait(True) # do this outside of thread every tick
except Queue.Full:
pass

def update_web_location_worker(self):
while True:
self.web_update_queue.get()
self.update_web_location()

def get_inventory_count(self, what):
response_dict = self.get_inventory()
Expand Down
Loading

0 comments on commit e8fd901

Please sign in to comment.