Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated item_filter in config.json.example to use item names instead item id's #1733

Merged
merged 5 commits into from
Jul 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"distance_unit": "km",
"reconnecting_timeout": 15,
"item_filter": {
"1": { "keep" : 100 },
"101": { "keep" : 10 },
"102": { "keep" : 30 },
"103": { "keep" : 30 },
"201": { "keep" : 30 },
"701": { "keep" : 100 }
"Pokeball": { "keep" : 100 },
Copy link
Contributor

Choose a reason for hiding this comment

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

We should raise an exception if there is something in this list that isn't a known item. Otherwise people will have a typo here. Raising that exception will save us having to answer lots of support issues.

"Potion": { "keep" : 10 },
"Super Potion": { "keep" : 20 },
"Hyper Potion": { "keep" : 30 },
"Revive": { "keep" : 30 },
"Razz Berry": { "keep" : 100 }
},
"evolve_all": "NONE",
"evolve_speed": 20,
Expand Down
7 changes: 7 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ def init_config():
parser.error("--catch_randomize_spin_factor is out of range! (should be 0 <= catch_randomize_spin_factor <= 1)")
return None

# item list config verification
item_list = json.load(open(os.path.join('data', 'items.json')))
for config_item_name, bag_count in config.item_filter.iteritems():
if config_item_name not in item_list.viewvalues():
parser.error('item "' + config_item_name + '" does not exist, spelling mistake? (check for valid item names in data/items.json)')
return None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay it has the check very early on before server connection (for fast feedback) hence the reason for the json.load

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed conflicts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great. This should probably use

parser.error("YOUR STRING")
return None

instead of raising though.

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

for item_id, bag_count in item_count_dict.iteritems():
item_name = self.bot.item_list[str(item_id)]
id_filter = self.bot.config.item_filter.get(str(item_id), 0)
id_filter = self.bot.config.item_filter.get(item_name, 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.bot.config.item_filter and bag_count > id_filter_keep:
if item_name in self.bot.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)
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)
)
message_template = "-- Discarded {}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("-- Failed to discard " + item_name, 'red')

def send_recycle_item_request(self, item_id, count):
self.bot.api.recycle_inventory_item(item_id=item_id, count=count)
Expand Down