Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pokestops / Evolves / Transfers Logged to DB #4232

Merged
merged 7 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from pokemongo_bot.inventory import Pokemon
from pokemongo_bot.item_list import Item
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.datastore import Datastore


class EvolvePokemon(BaseTask):
class EvolvePokemon(Datastore, BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def __init__(self, bot, config):
super(EvolvePokemon, self).__init__(bot, config)

def initialize(self):
self.api = self.bot.api
self.evolve_all = self.config.get('evolve_all', [])
Expand Down Expand Up @@ -113,6 +115,8 @@ def _execute_pokemon_evolve(self, pokemon, cache):
'xp': '?'
}
)
with self.bot.database as conn:
conn.execute('''INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))
awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)
inventory.candies().get(pokemon.pokemon_id).consume(pokemon.evolution_cost - awarded_candies)
inventory.pokemons().remove(pokemon.unique_id)
Expand Down
5 changes: 5 additions & 0 deletions pokemongo_bot/cell_workers/migrations/evolve_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from yoyo import step

step(
"CREATE TABLE evolve_log (pokemon text, iv real, cp real, dated datetime DEFAULT CURRENT_TIMESTAMP)"
)
5 changes: 5 additions & 0 deletions pokemongo_bot/cell_workers/migrations/pokestop_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from yoyo import step

step(
"CREATE TABLE pokestop_log (pokestop text, exp real, items text, dated datetime DEFAULT CURRENT_TIMESTAMP)"
)
5 changes: 5 additions & 0 deletions pokemongo_bot/cell_workers/migrations/transfer_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from yoyo import step

step(
"CREATE TABLE transfer_log (pokemon text, iv real, cp real, dated datetime DEFAULT CURRENT_TIMESTAMP)"
)
4 changes: 4 additions & 0 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ def work(self):
'items': items_awarded
}
)
with self.bot.database as conn:
conn.execute('''INSERT INTO pokestop_log (pokestop, exp, items) VALUES (?, ?, ?)''', (fort_name, str(experience_awarded), str(items_awarded)))
else:
self.emit_event(
'pokestop_empty',
formatted='Found nothing in pokestop {pokestop}.',
data={'pokestop': fort_name}
)
with self.bot.database as conn:
conn.execute('''INSERT INTO pokestop_log (pokestop) VALUES (?)''', (fort_name))
pokestop_cooldown = spin_details.get(
'cooldown_complete_timestamp_ms')
self.bot.fort_timeouts.update({fort["id"]: pokestop_cooldown})
Expand Down
9 changes: 7 additions & 2 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
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

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)
Expand Down Expand Up @@ -175,6 +178,8 @@ def release_pokemon(self, pokemon):
'dps': pokemon.moveset.dps
}
)
with self.bot.database as conn:
conn.execute('''INSERT INTO transfer_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))
action_delay(self.transfer_wait_min, self.transfer_wait_max)

def _get_release_config_for(self, pokemon):
Expand Down