diff --git a/configs/config.json.example b/configs/config.json.example index deec6d9e0b..408e699273 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -12,6 +12,7 @@ "initial_transfer": false, "location_cache": true, "distance_unit": "km", + "reconnecting_timeout": 15, "item_filter": { "1": { "keep" : 100 }, "101": { "keep" : 10 }, diff --git a/pokecli.py b/pokecli.py index c0e8c19963..8e80c9e439 100755 --- a/pokecli.py +++ b/pokecli.py @@ -32,7 +32,9 @@ import os import ssl import sys +import time from getpass import getpass +from pgoapi.exceptions import NotLoggedInException from pokemongo_bot import PokemonGoBot from pokemongo_bot import logger @@ -173,6 +175,13 @@ def init_config(): type=bool, default=False ) + parser.add_argument( + "-rt", + "--reconnecting_timeout", + help="Timeout between reconnecting if error occured (in minutes, e.g. 15)", + type=float, + default=15.0 + ) # Start to parse other attrs config = parser.parse_args() @@ -227,19 +236,27 @@ def main(): return logger.log('Configuration initialized', 'yellow') - try: - bot = PokemonGoBot(config) - bot.start() + finished = False + + while not finished: + try: + bot = PokemonGoBot(config) + bot.start() + + logger.log('Starting PokemonGo Bot....', 'green') - logger.log('Starting PokemonGo Bot....', 'green') + while True: + bot.take_step() - while True: - bot.take_step() + except KeyboardInterrupt: + logger.log('Exiting PokemonGo Bot', 'red') + finished = True + # TODO Add number of pokemon catched, pokestops visited, highest CP + # pokemon catched, etc. - except KeyboardInterrupt: - logger.log('Exiting PokemonGo Bot', 'red') - # TODO Add number of pokemon catched, pokestops visited, highest CP - # pokemon catched, etc. + except NotLoggedInException: + logger.log('[x] Error while connecting to the server, please wait %s minutes' % config.reconnecting_timeout, 'red') + time.sleep(config.reconnecting_timeout * 60) if __name__ == '__main__':