From f2a41d06f2307d1fa4a2c114e673d31dab5f00aa Mon Sep 17 00:00:00 2001 From: Ro Date: Fri, 19 Aug 2016 22:50:11 -0400 Subject: [PATCH] Log Transfers (#4310) missing from https://github.com/PokemonGoF/PokemonGo-Bot/pull/4285 --- .../cell_workers/transfer_pokemon.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/transfer_pokemon.py b/pokemongo_bot/cell_workers/transfer_pokemon.py index 9cc0526ff0..e51fd82710 100644 --- a/pokemongo_bot/cell_workers/transfer_pokemon.py +++ b/pokemongo_bot/cell_workers/transfer_pokemon.py @@ -5,11 +5,14 @@ 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.datastore import Datastore from operator import attrgetter -class TransferPokemon(BaseTask): +class TransferPokemon(Datastore, BaseTask): SUPPORTED_TASK_API_VERSION = 1 + def __init__(self, bot, config): + super(TransferPokemon, self).__init__(bot, config) def initialize(self): self.transfer_wait_min = self.config.get('transfer_wait_min', 1) self.transfer_wait_max = self.config.get('transfer_wait_max', 4) @@ -177,6 +180,24 @@ def release_pokemon(self, pokemon): 'dps': pokemon.moveset.dps } ) + with self.bot.database as conn: + c = conn.cursor() + c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='transfer_log'") + + result = c.fetchone() + + while True: + if result[0] == 1: + conn.execute('''INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp)) + break + else: + self.emit_event( + 'transfer_log', + sender=self, + level='info', + formatted="transfer_log table not found, skipping log" + ) + break action_delay(self.transfer_wait_min, self.transfer_wait_max) def _get_release_config_for(self, pokemon):