Skip to content

Commit

Permalink
Enable the exception, have a backup. for pokecli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
solderzzc committed Aug 7, 2016
1 parent 96fe1f2 commit 60f8eb4
Show file tree
Hide file tree
Showing 2 changed files with 479 additions and 76 deletions.
107 changes: 31 additions & 76 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,82 +51,37 @@
logger.setLevel(logging.INFO)

def main():
try:
logger.info('PokemonGO Bot v1.0')
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)

config = init_config()
if not config:
return

logger.info('Configuration initialized')
health_record = BotEvent(config)
health_record.login_success()

finished = False

while not finished:
try:
bot = PokemonGoBot(config)
bot.start()
tree = TreeConfigBuilder(bot, config.raw_tasks).build()
bot.workers = tree
bot.metrics.capture_stats()

bot.event_manager.emit(
'bot_start',
sender=bot,
level='info',
formatted='Starting bot...'
)

while True:
bot.tick()

except KeyboardInterrupt:
bot.event_manager.emit(
'bot_exit',
sender=bot,
level='info',
formatted='Exiting bot.'
)
finished = True
report_summary(bot)

except NotLoggedInException:
wait_time = config.reconnecting_timeout * 60
bot.event_manager.emit(
'api_error',
sender=bot,
level='info',
formmated='Log logged in, reconnecting in {:s}'.format(wait_time)
)
time.sleep(wait_time)
except ServerBusyOrOfflineException:
bot.event_manager.emit(
'api_error',
sender=bot,
level='info',
formatted='Server busy or offline'
)
except ServerSideRequestThrottlingException:
bot.event_manager.emit(
'api_error',
sender=bot,
level='info',
formatted='Server is throttling, reconnecting in 30 seconds'
)
time.sleep(30)

except GeocoderQuotaExceeded:
raise Exception("Google Maps API key over requests limit.")
except Exception as e:
# always report session summary and then raise exception
if bot:
report_summary(bot)

raise e
logger.info('PokemonGO Bot v1.0')
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)

config = init_config()
if not config:
return

logger.info('Configuration initialized')
health_record = BotEvent(config)
health_record.login_success()

finished = False

while not finished:
bot = PokemonGoBot(config)
bot.start()
tree = TreeConfigBuilder(bot, config.raw_tasks).build()
bot.workers = tree
bot.metrics.capture_stats()

bot.event_manager.emit(
'bot_start',
sender=bot,
level='info',
formatted='Starting bot...'
)

while True:
bot.tick()


def report_summary(bot):
if bot.metrics.start_time is None:
Expand Down
Loading

0 comments on commit 60f8eb4

Please sign in to comment.