Skip to content

Commit

Permalink
Catch_Log table check & database log events (#4280)
Browse files Browse the repository at this point in the history
* Catch log table checks

Ensuring catch_log table exists before inserting record to db

* Log events (for database stuff)

real quick

* Database log events

* register_event pokestop_log

* pokestop_log log event
  • Loading branch information
BreezeRo authored and joelgreen committed Aug 19, 2016
1 parent f002251 commit d9a5563
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,13 @@ def _register_events(self):
'error_caching_forts',
parameters=('path', )
)

# database shit
self.event_manager.register_event('catch_log')
self.event_manager.register_event('evolve_log')
self.event_manager.register_event('login_log')
self.event_manager.register_event('transfer_log')
self.event_manager.register_event('pokestop_log')

def tick(self):
self.health_record.heartbeat()
self.cell = self.get_meta_cell()
Expand Down
19 changes: 16 additions & 3 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,22 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):

)
with self.bot.database as conn:
conn.execute('''INSERT INTO catch_log (pokemon, cp, iv, encounter_id, pokemon_id) VALUES (?, ?, ?, ?, ?)''', (pokemon.name, pokemon.cp, pokemon.iv, str(encounter_id), pokemon.pokemon_id))
#conn.commit()
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='catch_log'")
result = c.fetchone()

while True:
if result[0] == 1:
conn.execute('''INSERT INTO catch_log (pokemon, cp, iv, encounter_id, pokemon_id) VALUES (?, ?, ?, ?, ?)''', (pokemon.name, pokemon.cp, pokemon.iv, str(encounter_id), pokemon.pokemon_id))
break
else:
self.emit_event(
'catch_log',
sender=self,
level='info',
formatted="catch_log table not found, skipping log"
)
break
user_data_caught = os.path.join(_base_dir, 'data', 'caught-%s.json' % self.bot.config.username)
with open(user_data_caught, 'ab') as outfile:
outfile.write(str(datetime.now()))
Expand Down Expand Up @@ -564,4 +578,3 @@ def generate_throw_quality_parameters(self, throw_parameters):
throw_parameters['normalized_reticle_size'] = 1.25 + 0.70 * random()
throw_parameters['normalized_hit_position'] = 0.0
throw_parameters['throw_type_label'] = 'OK'

5 changes: 5 additions & 0 deletions pokemongo_bot/event_handlers/colored_logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class ColoredLoggingHandler(EventHandler):
'bot_exit': 'red',
'bot_start': 'green',
'catch_limit': 'red',
'catch_log': 'magenta',
'config_error': 'red',
'egg_already_incubating': 'yellow',
'egg_hatched': 'green',
'evolve_log': 'magenta',
'future_pokemon_release': 'yellow',
'incubate': 'green',
'incubator_already_used': 'yellow',
Expand All @@ -27,6 +29,7 @@ class ColoredLoggingHandler(EventHandler):
'location_cache_error': 'yellow',
'location_cache_ignored': 'yellow',
'login_failed': 'red',
'login_log': 'magenta',
'login_successful': 'green',
'lucky_egg_error': 'red',
'move_to_map_pokemon_encounter': 'green',
Expand All @@ -46,12 +49,14 @@ class ColoredLoggingHandler(EventHandler):
'pokemon_release': 'green',
'pokemon_vanished': 'red',
'pokestop_empty': 'yellow',
'pokestop_log': 'magento',
'pokestop_searching_too_often': 'yellow',
'rename_pokemon': 'green',
'skip_evolve': 'yellow',
'softban': 'red',
'spun_pokestop': 'cyan',
'threw_berry_failed': 'red',
'transfer_log': 'magenta',
'unknown_spin_result': 'red',
'unset_pokemon_nickname': 'red',
'vip_pokemon': 'red',
Expand Down

0 comments on commit d9a5563

Please sign in to comment.