Skip to content

Commit

Permalink
Evolve / Transfer / Pokestop logs (DB) (#4285)
Browse files Browse the repository at this point in the history
* Log pokemon evolves to the database

with safety check on table existing

* Log pokestops to database

logs all pokestops to the database (will be used to limit pokestops per "time"), included safety check to ensure table exists before inserting

* evolve_log.py

* transfer_log.py

* pokestop_log.py

* Update CONTRIBUTORS.md
  • Loading branch information
BreezeRo authored Aug 19, 2016
1 parent 8f51a3e commit 7765abc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@
* umbreon222
* DeXtroTip
* rawgni
* Breeze Ro
23 changes: 22 additions & 1 deletion pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +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
Expand Down Expand Up @@ -114,6 +117,24 @@ def _execute_pokemon_evolve(self, pokemon, cache):
'xp': '?'
}
)
with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'")

result = c.fetchone()

while True:
if result[0] == 1:
conn.execute('''INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))
break
else:
self.emit_event(
'evolve_log',
sender=self,
level='info',
formatted="evolve_log table not found, skipping log"
)
break
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 IF NOT EXISTS 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 IF NOT EXISTS 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 IF NOT EXISTS transfer_log (pokemon text, iv real, cp real, dated datetime DEFAULT CURRENT_TIMESTAMP)"
)
21 changes: 20 additions & 1 deletion pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.base_dir import _base_dir
from utils import distance, format_time, fort_details
from pokemongo_bot.datastore import Datastore

SPIN_REQUEST_RESULT_SUCCESS = 1
SPIN_REQUEST_RESULT_OUT_OF_RANGE = 2
SPIN_REQUEST_RESULT_IN_COOLDOWN_PERIOD = 3
SPIN_REQUEST_RESULT_INVENTORY_FULL = 4


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

def __init__(self, bot, config):
super(SpinFort, self).__init__(bot, config)
def initialize(self):
self.ignore_item_count = self.config.get("ignore_item_count", False)
self.spin_wait_min = self.config.get("spin_wait_min", 2)
Expand Down Expand Up @@ -85,6 +88,22 @@ def work(self):
formatted='Found nothing in pokestop {pokestop}.',
data={'pokestop': fort_name}
)
with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='pokestop_log'")
result = c.fetchone()
while True:
if result[0] == 1:
conn.execute('''INSERT INTO pokestop_log (pokestop, exp, items) VALUES (?, ?, ?)''', (fort_name, str(experience_awarded), str(items_awarded)))
break
else:
self.emit_event(
'pokestop_log',
sender=self,
level='info',
formatted="pokestop_log table not found, skipping log"
)
break
pokestop_cooldown = spin_details.get(
'cooldown_complete_timestamp_ms')
self.bot.fort_timeouts.update({fort["id"]: pokestop_cooldown})
Expand Down

0 comments on commit 7765abc

Please sign in to comment.