Skip to content

Commit

Permalink
Item_filter format changed, supports itemcount (#1000)
Browse files Browse the repository at this point in the history
* disabling string parsing as structure is about to be changed

* Test functionallity

* Finished function item_filter with number limit

* new item_filter update example configs
  • Loading branch information
fredrik-hellmangroup authored and solderzzc committed Jul 26, 2016
1 parent 7e10307 commit 0ebdfc0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
9 changes: 8 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
"initial_transfer": 0,
"location_cache": true,
"distance_unit": "km",
"item_filter": "",
"item_filter": {
"1": { "keep" : 100 },
"101": { "keep" : 10 },
"102": { "keep" : 30 },
"103": { "keep" : 30 },
"201": { "keep" : 30 },
"701": { "keep" : 100 }
},
"evolve_all": "NONE",
"cp_min": 300,
"use_lucky_egg": false,
Expand Down
9 changes: 8 additions & 1 deletion configs/config.json.pokemons.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
"initial_transfer": 0,
"location_cache": true,
"distance_unit": "km",
"item_filter": "",
"item_filter": {
"1": { "keep" : 100 },
"101": { "keep" : 10 },
"102": { "keep" : 30 },
"103": { "keep" : 30 },
"201": { "keep" : 30 },
"701": { "keep" : 100 }
},
"evolve_all": "NONE",
"use_lucky_egg": false,
"evolve_captured": false,
Expand Down
4 changes: 0 additions & 4 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ def init_config():
parser.error("Needs either --use-location-cache or --location.")
return None

# When config.item_filter looks like "101,102,103" needs to be converted to ["101","102","103"]
if isinstance(config.item_filter, basestring):
config.item_filter= config.item_filter.split(",")

# create web dir if not exists
try:
os.makedirs(web_dir)
Expand Down
16 changes: 12 additions & 4 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,25 @@ def work(self):

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


# RECYCLING UNWANTED ITEMS
if str(item_id) in self.config.item_filter:
logger.log("-- Recycling " + str(item_count) + "x " + item_name + "...", 'green')
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 = item_count + self.bot.item_inventory_count(item_id)

This comment has been minimized.

Copy link
@alvarogzp

alvarogzp Jul 26, 2016

Contributor

This sum is not necessary (self.bot.item_inventory_count(item_id) already has the new items), and it is causing recycling to fail (trying to recycle more items than it has).

if str(item_id) in self.config.item_filter and new_bag_count >= id_filter_keep:
#RECYCLE_INVENTORY_ITEM
response_dict_recycle = self.bot.drop_item(item_id=item_id, count=item_count)
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' 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:
Expand Down

4 comments on commit 0ebdfc0

@pmwoodward3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last): File "pokecli.py", line 246, in <module> main() File "pokecli.py", line 237, in main bot.take_step() File "/opt/dev/pokemongo_bot/__init__.py", line 45, in take_step self.work_on_cell(cell, location) File "/opt/dev/pokemongo_bot/__init__.py", line 216, in work_on_cell hack_chain = worker.work() File "/opt/dev/pokemongo_bot/cell_workers/seen_fort_worker.py", line 76, in work id_filter = self.config.item_filter.get(str(item_id), 0) AttributeError: 'unicode' object has no attribute 'get'

Just got this while trying to get items from a pokestop, is this related to this commit?

@alvarogzp
Copy link
Contributor

@alvarogzp alvarogzp commented on 0ebdfc0 Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmwoodward3 yes, you have to update item_filter property in config.json to match the format in config.json.example

@pmwoodward3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, that fixed it, is there a list of all the items numbers?

@alvarogzp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmwoodward3 it's in data/items.json

Please sign in to comment.