Skip to content

Commit

Permalink
RecycleItemWorker implemented (runs on every tick) (PokemonGoF#1156)
Browse files Browse the repository at this point in the history
* RecycleItemWorker implemented (runs on every tick)

* moved RecycleItemWorker to a better place

* recycle item worker logging improved

* simplify if in item_inventory_count

* removing extra space
  • Loading branch information
douglascamata authored and MFizz committed Jul 29, 2016
1 parent a23b356 commit b66c43e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from initial_transfer_worker import InitialTransferWorker
from evolve_all_worker import EvolveAllWorker
from catch_visible_pokmeon_worker import CatchVisiblePokemonWorker
from recycle_items_worker import RecycleItemsWorker
53 changes: 53 additions & 0 deletions pokemongo_bot/cell_workers/recycle_items_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from pokemongo_bot import logger


class RecycleItemsWorker(object):

def __init__(self, bot):
self.bot = bot
self.api = bot.api
self.config = bot.config
self.item_list = bot.item_list

def work(self):
logger.log('Starting to recycle items...', 'yellow')
item_count_dict = self.bot.item_inventory_count('all')

for item_id, bag_count in item_count_dict.iteritems():
item_name = self.item_list[str(item_id)]
id_filter = self.config.item_filter.get(str(item_id), 0)
if id_filter is not 0:
id_filter_keep = id_filter.get('keep', 20)

bag_count = self.bot.item_inventory_count(item_id)
if str(item_id) in self.config.item_filter and bag_count > id_filter_keep:
items_recycle_count = bag_count - id_filter_keep

response_dict_recycle = self.send_recycle_item_request(
item_id=item_id,
count=items_recycle_count
)

result = response_dict_recycle.get('responses', {}) \
.get('RECYCLE_INVENTORY_ITEM', {}) \
.get('result', 0)

if result == 1: # Request success
message_template = "-- Recycled {}x {} (keeps only {} maximum) "
message = message_template.format(
str(items_recycle_count),
item_name,
str(id_filter_keep)
)
logger.log(message, 'green')
else:
logger.log("-- Failed to recycle " + item_name + "has failed!", 'red')
logger.log('Finished.', 'yellow')

def send_recycle_item_request(self, item_id, count):
self.api.recycle_inventory_item(item_id=item_id, count=count)
inventory_req = self.api.call()

# Example of good request response
#{'responses': {'RECYCLE_INVENTORY_ITEM': {'result': 1, 'new_count': 46}}, 'status_code': 1, 'auth_ticket': {'expire_timestamp_ms': 1469306228058L, 'start': '/HycFyfrT4t2yB2Ij+yoi+on778aymMgxY6RQgvrGAfQlNzRuIjpcnDd5dAxmfoTqDQrbz1m2dGqAIhJ+eFapg==', 'end': 'f5NOZ95a843tgzprJo4W7Q=='}, 'request_id': 8145806132888207460L}
return inventory_req
25 changes: 0 additions & 25 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,7 @@ def work(self):

for item_id, item_count in tmp_count_items.iteritems():
item_name = self.item_list[str(item_id)]

logger.log('- ' + str(item_count) + "x " + item_name + " (Total: " + str(self.bot.item_inventory_count(item_id)) + ")", 'yellow')


# RECYCLING UNWANTED ITEMS
id_filter = self.config.item_filter.get(str(item_id), 0)
if id_filter is not 0:
id_filter_keep = id_filter.get('keep',20)
new_bag_count = self.bot.item_inventory_count(item_id)
if str(item_id) in self.config.item_filter and new_bag_count > id_filter_keep:
#RECYCLE_INVENTORY_ITEM
items_recycle_count = new_bag_count - id_filter_keep
logger.log("-- Recycling " + str(items_recycle_count) + "x " + item_name + " to match filter "+ str(id_filter_keep) +"...", 'green')
response_dict_recycle = self.bot.drop_item(item_id=item_id, count=items_recycle_count)

result = 0
if response_dict_recycle and \
'responses' in response_dict_recycle and \
'RECYCLE_INVENTORY_ITEM' in response_dict_recycle['responses'] and \
'result' in response_dict_recycle['responses']['RECYCLE_INVENTORY_ITEM']:
result = response_dict_recycle['responses']['RECYCLE_INVENTORY_ITEM']['result']

if result is 1: # Request success
logger.log("-- Recycled " + item_name + "!", 'green')
else:
logger.log("-- Recycling " + item_name + "has failed!", 'red')
else:
logger.log("[#] Nothing found.", 'yellow')

Expand Down

0 comments on commit b66c43e

Please sign in to comment.