Skip to content

Commit

Permalink
Merge pull request #5490 from JSchwerberg/py3convert
Browse files Browse the repository at this point in the history
Python 3 Compatibility
  • Loading branch information
javajohnHub authored Sep 17, 2016
2 parents 5ccaf93 + 16e4f79 commit 4ef0417
Show file tree
Hide file tree
Showing 42 changed files with 140 additions and 131 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var/
*.egg-info/
.installed.cfg
*.egg
*.orig
*.bak

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ If you do not want any data to be gathered, you can turn off this feature by set
* mzupan
* gnekic(GeXx)
* Shoh
* JSchwerberg
* luizperes
* brantje
* VirtualSatai
Expand Down
6 changes: 4 additions & 2 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import json
import logging
import os
import six
import ssl
import sys
import time
Expand Down Expand Up @@ -164,8 +165,9 @@ def get_commit_hash():
return f.read()[:8]

try:
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)
if six.PY2:
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)

logger.info('PokemonGO Bot v1.0')
logger.info('commit: ' + get_commit_hash())
Expand Down
33 changes: 17 additions & 16 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import

import datetime
import json
Expand All @@ -19,27 +20,28 @@
from pgoapi.utilities import f2i, get_cell_ids
from s2sphere import Cell, CellId, LatLng

import cell_workers
from base_task import BaseTask
from plugin_loader import PluginLoader
from api_wrapper import ApiWrapper
from cell_workers.utils import distance
from event_manager import EventManager
from human_behaviour import sleep
from item_list import Item
from metrics import Metrics
from sleep_schedule import SleepSchedule
from . import cell_workers
from .base_task import BaseTask
from .plugin_loader import PluginLoader
from .api_wrapper import ApiWrapper
from .cell_workers.utils import distance
from .event_manager import EventManager
from .human_behaviour import sleep
from .item_list import Item
from .metrics import Metrics
from .sleep_schedule import SleepSchedule
from pokemongo_bot.event_handlers import SocketIoHandler, LoggingHandler, SocialHandler
from pokemongo_bot.socketio_server.runner import SocketIoRunner
from pokemongo_bot.websocket_remote_control import WebsocketRemoteControl
from pokemongo_bot.base_dir import _base_dir
from worker_result import WorkerResult
from tree_config_builder import ConfigException, MismatchTaskApiVersion, TreeConfigBuilder
from inventory import init_inventory, player
from .worker_result import WorkerResult
from .tree_config_builder import ConfigException
from .tree_config_builder import MismatchTaskApiVersion
from .tree_config_builder import TreeConfigBuilder
from .inventory import init_inventory, player
from sys import platform as _platform
from pgoapi.protos.POGOProtos.Enums import BadgeType_pb2
from pgoapi.exceptions import AuthException
import struct


class FileIOException(Exception):
Expand Down Expand Up @@ -1317,7 +1319,7 @@ def heartbeat(self):
# store awarded_badges reponse to be used in a task or part of heartbeat
self._awarded_badges = responses['responses']['CHECK_AWARDED_BADGES']

if self._awarded_badges.has_key('awarded_badges'):
if 'awarded_badges' in self._awarded_badges:
i = 0
for badge in self._awarded_badges['awarded_badges']:
badgelevel = self._awarded_badges['awarded_badge_levels'][i]
Expand Down Expand Up @@ -1407,7 +1409,6 @@ def _load_recent_forts(self):
cached_recent_forts = json.load(f)
except (IOError, ValueError) as e:
self.logger.info('[x] Error while opening cached forts: %s' % e)
pass
except:
raise FileIOException("Unexpected error opening {}".cached_forts_path)

Expand Down
8 changes: 5 additions & 3 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from __future__ import absolute_import
import time
import logging
import random, base64, struct
import hashlib
import os
import json
from pgoapi.exceptions import (ServerSideRequestThrottlingException,
NotLoggedInException, ServerBusyOrOfflineException,
NoPlayerPositionSetException, EmptySubrequestChainException,
UnexpectedResponseException)
from pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi
from pgoapi.pgoapi import PGoApi
from pgoapi.pgoapi import PGoApiRequest
from pgoapi.pgoapi import RpcApi
from pgoapi.protos.POGOProtos.Networking.Requests.RequestType_pb2 import RequestType
from pgoapi.utilities import get_time
from human_behaviour import sleep, gps_noise_rng
from .human_behaviour import sleep, gps_noise_rng
from pokemongo_bot.base_dir import _base_dir


Expand Down
57 changes: 29 additions & 28 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
# -*- coding: utf-8 -*-

from evolve_pokemon import EvolvePokemon
from incubate_eggs import IncubateEggs
from move_to_fort import MoveToFort
from move_to_map_pokemon import MoveToMapPokemon
from nickname_pokemon import NicknamePokemon
from pokemon_catch_worker import PokemonCatchWorker
from pokemon_hunter import PokemonHunter
from pokemon_optimizer import PokemonOptimizer
from transfer_pokemon import TransferPokemon
from recycle_items import RecycleItems
from spin_fort import SpinFort
from handle_soft_ban import HandleSoftBan
from follow_path import FollowPath
from follow_spiral import FollowSpiral
from collect_level_up_reward import CollectLevelUpReward
from follow_cluster import FollowCluster
from update_live_stats import UpdateLiveStats
from update_live_inventory import UpdateLiveInventory
from catch_pokemon import CatchPokemon
from complete_tutorial import CompleteTutorial
from random_pause import RandomPause
from update_web_inventory import UpdateWebInventory
from random_alive_pause import RandomAlivePause
from show_best_pokemon import ShowBestPokemon
from telegram_task import TelegramTask
from use_incense import UseIncense
from camp_fort import CampFort
from discord_task import DiscordTask
from __future__ import absolute_import
from .evolve_pokemon import EvolvePokemon
from .incubate_eggs import IncubateEggs
from .move_to_fort import MoveToFort
from .move_to_map_pokemon import MoveToMapPokemon
from .nickname_pokemon import NicknamePokemon
from .pokemon_catch_worker import PokemonCatchWorker
from .pokemon_hunter import PokemonHunter
from .pokemon_optimizer import PokemonOptimizer
from .transfer_pokemon import TransferPokemon
from .recycle_items import RecycleItems
from .spin_fort import SpinFort
from .handle_soft_ban import HandleSoftBan
from .follow_path import FollowPath
from .follow_spiral import FollowSpiral
from .collect_level_up_reward import CollectLevelUpReward
from .follow_cluster import FollowCluster
from .update_live_stats import UpdateLiveStats
from .update_live_inventory import UpdateLiveInventory
from .catch_pokemon import CatchPokemon
from .complete_tutorial import CompleteTutorial
from .random_pause import RandomPause
from .update_web_inventory import UpdateWebInventory
from .random_alive_pause import RandomAlivePause
from .show_best_pokemon import ShowBestPokemon
from .telegram_task import TelegramTask
from .use_incense import UseIncense
from .camp_fort import CampFort
from .discord_task import DiscordTask
3 changes: 2 additions & 1 deletion pokemongo_bot/cell_workers/catch_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import

import json
import os
Expand All @@ -10,7 +11,7 @@
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.item_list import Item
from pokemongo_bot import inventory
from utils import fort_details, distance, format_time
from .utils import fort_details, distance, format_time
from pokemongo_bot.base_dir import _base_dir
from pokemongo_bot.constants import Constants
from pokemongo_bot.inventory import Pokemons
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from random import uniform

from pokemongo_bot import inventory
from pokemongo_bot.human_behaviour import sleep, action_delay
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/follow_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.cell_workers.utils import find_biggest_cluster
from pokemongo_bot.base_task import BaseTask
from random import uniform

class FollowCluster(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand Down
7 changes: 5 additions & 2 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import gpxpy
import gpxpy.gpx
import json
import time
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.cell_workers.utils import distance, i2f, format_dist
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.cell_workers.utils import format_dist
from pokemongo_bot.cell_workers.utils import i2f
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.walkers.walker_factory import walker_factory
from pokemongo_bot.worker_result import WorkerResult
from pgoapi.utilities import f2i
from random import uniform
from utils import getSeconds, format_dist
from .utils import getSeconds, format_dist
from datetime import datetime as dt, timedelta

STATUS_MOVING = 0
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/follow_spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _generate_spiral(starting_lat, starting_lng, step_size, step_limit):

def work(self):
if not self.next_point:
self.next_point = self.points.next()
self.next_point = next(self.points)
point = self.next_point
step_walker = StepWalker(self.bot, point['lat'], point['lng'])
if step_walker.step():
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/incubate_eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.worker_result import WorkerResult
from functools import reduce


class IncubateEggs(BaseTask):
Expand Down
3 changes: 2 additions & 1 deletion pokemongo_bot/cell_workers/move_to_fort.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import

from pokemongo_bot import inventory
from pokemongo_bot.constants import Constants
from pokemongo_bot.walkers.walker_factory import walker_factory
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.base_task import BaseTask
from utils import distance, format_dist, fort_details
from .utils import distance, format_dist, fort_details
from datetime import datetime, timedelta


Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/nickname_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import json
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.human_behaviour import sleep, action_delay
from pokemongo_bot.inventory import pokemons, Pokemon, Attack
from pokemongo_bot.inventory import Attack
from pokemongo_bot.inventory import Pokemon
from pokemongo_bot.inventory import pokemons

import re

Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import os
import time
import json
import logging
import sys

from random import random, randrange, uniform
Expand All @@ -14,7 +14,7 @@
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.base_dir import _base_dir
from datetime import datetime, timedelta
from utils import getSeconds
from .utils import getSeconds

from pprint import pprint

Expand Down
8 changes: 4 additions & 4 deletions pokemongo_bot/cell_workers/recycle_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ def work(self):

if not (self.max_balls_keep is None):
this_worker_result = self.recycle_excess_category_max(self.max_balls_keep, [1,2,3,4])
if this_worker_result <> WorkerResult.SUCCESS:
if this_worker_result != WorkerResult.SUCCESS:
worker_result = this_worker_result

if not (self.max_potions_keep is None):
this_worker_result = self.recycle_excess_category_max(self.max_potions_keep, [101,102,103,104])
if this_worker_result <> WorkerResult.SUCCESS:
if this_worker_result != WorkerResult.SUCCESS:
worker_result = this_worker_result

if not (self.max_berries_keep is None):
this_worker_result = self.recycle_excess_category_max(self.max_berries_keep, [701,702,703,704,705])
if this_worker_result <> WorkerResult.SUCCESS:
if this_worker_result != WorkerResult.SUCCESS:
worker_result = this_worker_result

if not (self.max_revives_keep is None):
this_worker_result = self.recycle_excess_category_max(self.max_revives_keep, [201,202])
if this_worker_result <> WorkerResult.SUCCESS:
if this_worker_result != WorkerResult.SUCCESS:
worker_result = this_worker_result

for item_in_inventory in inventory.items().all():
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/show_best_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ctypes
from datetime import datetime, timedelta

from pokemongo_bot import inventory
Expand Down
3 changes: 2 additions & 1 deletion pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import

import sys
import time
Expand All @@ -11,7 +12,7 @@
from pokemongo_bot.human_behaviour import action_delay
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.base_task import BaseTask
from utils import distance, format_time, fort_details
from .utils import distance, format_time, fort_details

SPIN_REQUEST_RESULT_SUCCESS = 1
SPIN_REQUEST_RESULT_OUT_OF_RANGE = 2
Expand Down
4 changes: 0 additions & 4 deletions pokemongo_bot/cell_workers/telegram_task.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from datetime import timedelta
import os
import json
import telegram
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.base_dir import _base_dir
Expand Down
16 changes: 8 additions & 8 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
import os

from pokemongo_bot import inventory
from pokemongo_bot.human_behaviour import action_delay
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.inventory import Pokemons, Pokemon, Attack
from pokemongo_bot.inventory import Attack
from pokemongo_bot.inventory import Pokemon
from pokemongo_bot.inventory import Pokemons
from operator import attrgetter
from random import randrange

Expand Down Expand Up @@ -154,11 +154,11 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False):
release_config = self._get_release_config_for(pokemon.name)

if (keep_best_mode
and not release_config.has_key('never_release')
and not release_config.has_key('always_release')
and not release_config.has_key('release_below_cp')
and not release_config.has_key('release_below_iv')
and not release_config.has_key('release_below_ivcp')):
and 'never_release' not in release_config
and 'always_release' not in release_config
and 'release_below_cp' not in release_config
and 'release_below_iv' not in release_config
and 'release_below_ivcp' not in release_config):
return True

cp_iv_logic = release_config.get('logic')
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/update_live_inventory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ctypes
import logging
from datetime import datetime, timedelta

Expand Down
Loading

0 comments on commit 4ef0417

Please sign in to comment.