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

Fixing ITEM_FILTER and Attribute Error: no position Issues #638

Merged
merged 10 commits into from
Jul 25, 2016
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ $ git submodule update
```

### Installation Windows

(change master to dev for the newer version)

On Windows, you will need to install PyYaml through the installer and not through requirements.txt.
Expand Down
13 changes: 6 additions & 7 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def init_config():
"-if",
"--item_filter",
help=
"Pass a list of unwanted items to recycle when collected at a Pokestop (e.g, \"101,102,103,104\" to recycle potions when collected)",
type=str,
"Pass a list of unwanted items to recycle when collected at a Pokestop (e.g, SYNTAX FOR CONFIG.JSON : [\"101\",\"102\",\"103\",\"104\"] to recycle potions when collected, SYNTAX FOR CONSOLE ARGUMENT : \"101\",\"102\",\"103\",\"104\")",
type=list,
default=[])

parser.add_argument("-ev",
Expand Down Expand Up @@ -170,13 +170,14 @@ def init_config():
parser.error("Needs either --use-location-cache or --location.")
return None

if config.item_filter:
config.item_filter = [str(item_id) for item_id in config.item_filter.split(',')]

config.release_config = {}
if os.path.isfile(release_config_json):
with open(release_config_json) as data:
config.release_config.update(json.load(data))
if isinstance(config.item_filter, basestring):
#When config.item_filter looks like "101,102,103" needs to be converted to ["101","102","103"]
config.item_filter= config.item_filter.split(",")


# create web dir if not exists
try:
Expand All @@ -190,12 +191,10 @@ def init_config():

return config


def main():
# log settings
# log format
#logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')

sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)

Expand Down
19 changes: 11 additions & 8 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ def item_inventory_count(self, id):
return item_count

def _set_starting_position(self):


has_position = False

if self.config.test:
# TODO: Add unit tests
return
Expand All @@ -368,22 +370,25 @@ def _set_starting_position(self):
'utf-8')))
logger.log('[x] Position in-game set as: {}'.format(self.position))
logger.log('')
has_position = True
return
except:
logger.log('[x] The location given using -l could not be parsed. Checking for a cached location.')
pass

if self.config.location_cache and not self.config.location:
if self.config.location_cache and not has_position:
try:
#
# save location flag used to pull the last known location from
# the location.json
logger.log('[x] Parsing cached location...')
with open('data/last-location-%s.json' %
(self.config.username)) as f:
location_json = json.load(f)

self.position = (location_json['lat'],
location_json['lng'], 0.0)
print(self.position)
self.api.set_position(*self.position)

logger.log('')
Expand All @@ -393,14 +398,12 @@ def _set_starting_position(self):
'[x] Last in-game location was set as: {}'.format(
self.position))
logger.log('')


has_position = True
return
except:
if not self.config.location:
sys.exit(
"No cached Location. Please specify initial location.")
else:
pass
sys.exit(
"No cached Location. Please specify initial location.")

def _get_pos_by_name(self, location_name):
# Check if the given location is already a coordinate.
Copy link
Contributor

Choose a reason for hiding this comment

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

release_config.json.example → release_config.json
This should not be tracked.

Invitation sent, please join our team.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you :)

Copy link
Contributor

Choose a reason for hiding this comment

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

You are more than welcome.

Expand Down