forked from PokemonGoF/PokemonGo-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RecycleItemWorker implemented (runs on every tick) (PokemonGoF#1156)
* 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
1 parent
a23b356
commit b66c43e
Showing
3 changed files
with
54 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters