Skip to content

Commit

Permalink
Fix spin fort task (#5160)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin5 authored and solderzzc committed Sep 4, 2016
1 parent 1b6f43a commit 99f686d
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import json
import os
import sys
import time

Expand All @@ -13,7 +11,6 @@
from pokemongo_bot.human_behaviour import action_delay
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.base_dir import _base_dir
from utils import distance, format_time, fort_details

SPIN_REQUEST_RESULT_SUCCESS = 1
Expand All @@ -27,6 +24,7 @@ class SpinFort(BaseTask):

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 @@ -98,22 +96,20 @@ def work(self):
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()
result = c.fetchone()
c.execute("SELECT DISTINCT COUNT(pokestop) FROM pokestop_log WHERE dated >= datetime('now','-1 day')")
if c.fetchone()[0]>=self.config.get('daily_spin_limit',2000):
if c.fetchone()[0] >= self.config.get('daily_spin_limit', 2000):
self.emit_event('spin_limit', formatted='WARNING! You have reached your daily spin limit')
sys.exit(2)
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"
)
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')
Expand Down Expand Up @@ -164,22 +160,20 @@ def work(self):
with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='softban_log'")
result = c.fetchone()
result = c.fetchone()

if result[0] == 1:
source = str("PokemonCatchWorker")
status = str("Possible Softban")
conn.execute('''INSERT INTO softban_log (status, source) VALUES (?, ?)''', (status, source))
else:
self.emit_event(
'softban_log',
sender=self,
level='info',
formatted="softban_log table not found, skipping log"
)

self.emit_event('softban_log',
sender=self,
level='info',
formatted="softban_log table not found, skipping log")

self.bot.fort_timeouts[fort["id"]] = (time.time() + 300) * 1000 # Don't spin for 5m

return WorkerResult.ERROR
action_delay(self.spin_wait_min, self.spin_wait_max)

Expand All @@ -190,10 +184,8 @@ def work(self):

def get_forts_in_range(self):
forts = self.bot.get_forts(order_by_distance=True)
now = time.time() * 1000
forts = filter(lambda x: x.get('cooldown_complete_timestamp_ms', 0) < now, forts)
forts = filter(lambda fort: fort["id"] not in self.bot.fort_timeouts, forts)

# forts = filter(lambda fort: fort["id"] not in self.bot.fort_timeouts, forts)
if self.bot.config.replicate_gps_xy_noise:
forts = filter(lambda fort: distance(
self.bot.noised_position[0],
Expand Down Expand Up @@ -224,7 +216,7 @@ def get_items_awarded_from_fort_spinned(self, response_dict):
item_awarded_name = inventory.Items.name_for(item_awarded_id)
item_awarded_count = item_awarded['item_count']

if not item_awarded_name in tmp_count_items:
if item_awarded_name not in tmp_count_items:
tmp_count_items[item_awarded_name] = item_awarded_count
else:
tmp_count_items[item_awarded_name] += item_awarded_count
Expand Down

0 comments on commit 99f686d

Please sign in to comment.