Skip to content

Commit

Permalink
Fixing ITEM_FILTER and Attribute Error: no position Issues (PokemonGo…
Browse files Browse the repository at this point in the history
…F#638)

* FIXING filter_item issues

* FIXING filter_item issues

* FIXING filter_item issues

* FIXING filter_item issues

* fixing no position Attribute found

* Fixing Filter_item issues, and no attribute position

* Delete release_config.json
  • Loading branch information
dmateusp authored and MFizz committed Jul 29, 2016
1 parent 48deae6 commit 9556c1a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 82 deletions.
125 changes: 58 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

# PokemonGo-Bot
The Pokemon Go Bot, baking with community.
## Help Needed on [Desktop Version](https://github.com/PokemonGoF/PokemonGo-Bot-Desktop)

## Project Chat
We use [Slack](https://slack.com) as a web chat. [Click here to join the chat!](https://pokemongo-bot.herokuapp.com)
## Breaking Changes
You need modify config.json (config.json.example for example) then pokecli.py --config config.json
You need modify config.json (config.json.example for example) then pokecli.py --config config.json
Please clean up your old clone if you have issue, and following the [install instruction](https://github.com/PokemonGoF/PokemonGo-Bot#installation).

## About dev/master Branch
Dev branch has the most up-to-date features, but be aware that there might be some broken changes. Your contribution and PR for fixes are warm welcome.
Master branch is the stable branch.
No PR on master branch to keep things easier.
Dev branch has most up to date feature and even everyone handle the part well, still, will have broken changes. Your test contribute and PR for fix are warm welcome.
Master branch is the stable branch.
No PR on master branch to keep things easier.
## Table of Contents
- [Project Chat](#project-chat)
- [Features](#features)
Expand All @@ -45,7 +45,7 @@ No PR on master branch to keep things easier.
* Limit the step to farm specific area for pokestops
* Use the ball you have to catch, don't if you don't have
* Rudimentary IV Functionality filter
* Auto switch mode (Full of item then catch, no ball useable then farm)
* Auto switch mode(Full of item then catch, no ball useable then farm)
* Ignore certain pokemon filter
* Use superior ball types when necessary
* When out of normal pokeballs, use the next type of ball unless there are less than 10 of that type, in which case switch to farm mode
Expand All @@ -62,9 +62,7 @@ No PR on master branch to keep things easier.
- [ ] Hatch eggs
- [ ] Incubate eggs
- [ ] Use candy

## Gym Battles
This bot takes a strong stance against automating gym battles. Botting gyms will have a negative effect on most players and thus the game as a whole. We will thus never accept contributions or changes containing code specific for gym battles.
- [ ] Fight Gym

## Installation

Expand All @@ -73,62 +71,54 @@ This bot takes a strong stance against automating gym battles. Botting gyms will
- [Python 2.7.x](http://docs.python-guide.org/en/latest/starting/installation/)
- [pip](https://pip.pypa.io/en/stable/installing/)
- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- [virtualenv](https://virtualenv.pypa.io/en/stable/installation/) (Recommended)
- [virtualenv](https://virtualenv.pypa.io/en/stable/installation/) (Optional)
- [docker](https://docs.docker.com/engine/installation/) (Optional)
- [protobuf 3](https://github.com/google/protobuf) (OS Dependent, see below)

### Note on virtualenv
We recommend you use virtualenv, not only will this tool keep your OS clean from all the python plugins.
It also provide an virtual space for more than 1 instance!

### Protobuf 3 installation

- OS X: `brew update && brew install --devel protobuf`
- Windows: Download protobuf 3.0: [here](https://github.com/google/protobuf/releases/download/v3.0.0-beta-4/protoc-3.0.0-beta-4-win32.zip) and unzip `bin/protoc.exe` into a folder in your PATH.
- Linux: `sudo apt-get install python-protobuf`
- Linux: `apt-get install python-protobuf`

### Note on branch
Please keep in mind that master is not always up-to-date whereas 'dev' is. In the installation note below change `master` to `dev` if you want to get and use the latest version.
Please keep in mind that master is not always up to date whereas 'dev' is. In the installation note below change `master` to `dev` if you want to get the latest version.

### Installation Linux
(change master to dev for the latest version)
(change master to dev for the newer version)

```
$ git clone -b master https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ virtualenv .
$ source bin/activate
$ git clone -b master https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ pip install -r requirements.txt
$ git submodule init
$ git submodule update
```

### Installation Mac
(change master to dev for the latest version)

Make sure you install the following first:
[Requirements](https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Installation)
(change master to dev for the newer version)

```
$ git clone -b master https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ virtualenv .
$ source bin/activate
$ git clone -b master https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ virtualenv .
$ source bin/activate
$ pip install -r requirements.txt
$ git submodule init
$ git submodule update
```

### Installation Windows
(change master to dev for the latest version)

(change master to dev for the newer version)

On Windows, you will need to install PyYaml through the installer and not through requirements.txt.

##### Windows vista, 7, 8:
Go to : http://pyyaml.org/wiki/PyYAML , download the right version for your pc and install it

##### Windows 10:
Go to [this](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyyaml) page and download: PyYAML-3.11-cp27-cp27m-win32.whl
Go to [this](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyyaml) page and download: PyYAML-3.11-cp27-cp27m-win32.whl
(If running 64-bit python or if you get a 'not a supported wheel on this platform' error,
download the 64 bit version instead: PyYAML-3.11-cp27-cp27m-win_amd64.whl )

Expand All @@ -139,13 +129,11 @@ $ pip install PyYAML-3.11-cp27-cp27m-win32.whl
// (replace PyYAML-3.11-cp27-cp27m-win32.whl with PyYAML-3.11-cp27-cp27m-win_amd64.whl
```

After this, just do:
After this, just do :

```
$ git clone -b master https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ virtualenv .
$ source bin/activate
$ git clone -b master https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ pip install -r requirements.txt
$ git submodule init
$ git submodule update
Expand All @@ -154,11 +142,11 @@ $ git submodule update
### Develop PokemonGo-Bot

```
$ git clone -b dev https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ virtualenv .
$ source bin/activate
$ pip install -r requirements.txt
$ git clone -b dev https://github.com/PokemonGoF/PokemonGo-Bot
$ cd PokemonGo-Bot
$ virtualenv .
$ source bin/activate
$ pip install -r requirements.txt
$ git submodule init
$ git submodule update
```
Expand All @@ -177,20 +165,20 @@ This project uses Google Maps. There's one map coupled with the project, but as
6. After the code done, will update here how to replace.

### Python possible bug
If you encounter problems with the module `ssl` and it's function `_create_unverified_context`, just comment it. (Solution available in Python 2.7.11)
In order to comment out the function and the module, please follow the instructions below:
If you encounter problems with the module `ssl` and it function `_create_unverified_context`. Just comment it. (Solution available in Python 2.7.11)
To do it follow instruction below :
- edit `pokecli.py`
- put `#` before `if` (line 43) and `ssl` (line 44)
- save it

Please keep in mind that this fix is only necessary if your python version don't have the `_create_unverified_context` argument in the ssl module.
Please keep in mind that this fix is necessary only if your python version don't have the `_create_unverified_context` argument in ssl module.

## Update
To update your project do: `git pull` in the project folder

## Usage (up-to-date)
## Usage (up to date)
1/ copy `config.json.example` to `config.json` and `release_config.json.example` to `release_config.json`.
2/ Edit `config.json` and replace `auth_service`, `username`, `password`, `location` and `gmapkey` with your parameters (other keys are optional, check `Advance Configuration` below)
2/ Edit `config.json` and replace `auth_service`, `username`, `password`, `location` and `gmapkey` with your parameters (others keys are optional, check `Advance Configuration` below)

## Advance Configuration
- `max_steps` :
Expand All @@ -199,21 +187,25 @@ To update your project do: `git pull` in the project folder
- `debug` : Let the default value here except if you are developper
- `test` : Let the default value here except if you are developper
- `initial_transfer` : Set this to 1 if you want to transfer pokemon
- `location_cache` :
- `location_cache` :
- `distance_unit` :
- `item_filter` :
- `evolve_all` : Set to true to evolve pokemons if possible
- `evolve_all` : Set to true to evolve pokemon if possible
- `use_lucky_egg` : Set to true to use lucky egg (if available) before evolve_all

### Evolve All Configuration
By setting the `evolve_all` attribute in config.json, you can instruct the bot to automatically
evolve specified pokemons on startup. This is especially useful for batch-evolving after popping up
a lucky egg (currently this needs to be done manually).

a lucky egg.

A lucky egg can be used before evolving by setting the `use_lucky_egg` to true in config.json. If a
lucky egg is not available and "use_lucky_egg" is set to true, evolving will be skipped.

The evolve all mechanism evolves only higher CP pokemons. It does this by first ordering them from high-to-low CP.
It will also automatically transfer the evolved pokemons based on the release configuration.

Examples on how to use (set in config.json):

1. "evolve_all": "all"
Will evolve ALL pokemons.
2. "evolve_all": "Pidgey,Weedle"
Expand All @@ -223,23 +215,23 @@ To update your project do: `git pull` in the project folder
## How to run with Docker

## How to add/discover new API
The example is [here](https://github.com/PokemonGoF/PokemonGo-Bot/commit/46e2352ce9f349cc127a408959679282f9999585)
1. Check the type of your API request in [POGOProtos](https://github.com/AeonLucid/POGOProtos/blob/eeccbb121b126aa51fc4eebae8d2f23d013e1cb8/src/POGOProtos/Networking/Requests/RequestType.proto) For example: RECYCLE_INVENTORY_ITEM
The example is [here](https://github.com/PokemonGoF/PokemonGo-Bot/commit/46e2352ce9f349cc127a408959679282f9999585)
1. Check the type of your API request in [POGOProtos](https://github.com/AeonLucid/POGOProtos/blob/eeccbb121b126aa51fc4eebae8d2f23d013e1cb8/src/POGOProtos/Networking/Requests/RequestType.proto) For example: RECYCLE_INVENTORY_ITEM
2. Convert to the api call in pokemongo_bot/__init__.py, RECYCLE_INVENTORY_ITEM change to self.api.recycle_inventory_item
```
def drop_item(self,item_id,count):
self.api.recycle_inventory_item(...............)
```
3. Where is the param list?
3. Where is the param list?
You need check this [Requests/Messages/RecycleInventoryItemMessage.proto](https://github.com/AeonLucid/POGOProtos/blob/eeccbb121b126aa51fc4eebae8d2f23d013e1cb8/src/POGOProtos/Networking/Requests/Messages/RecycleInventoryItemMessage.proto)
4. Then our final api call is
4. Then our final api call is
```
def drop_item(self,item_id,count):
self.api.recycle_inventory_item(item_id=item_id,count=count)
inventory_req = self.api.call()
print(inventory_req)
```
5. You can now debug on the log to see if get what you need
```
5. You can now debug on the log to see if get what you need

## How to set up a simple webserver with nginx
### Nginx on Ubuntu 14.x, 16.x
Expand Down Expand Up @@ -277,7 +269,7 @@ Try to generate an [app password](!https://support.google.com/accounts/answer/18
```
-p "<your-app-password>"
```
This error mostly occurs for those who are using 2 factor authentication, but either way, for the purpose of security it would be nice to have a separate password for the bot app.
This error is mostly occurs for those who using 2 factor authentication but either way for the purpose of security would be nice to have a separate password for the bot app.


### FLEE
Expand All @@ -295,7 +287,7 @@ Create the following filter
```
./data/catch-ignore.yml
```
It's a yaml file with a list of names so make it look like
Its a yaml file with a list of names so make it look like
```
ignore:
- Pidgey
Expand All @@ -306,15 +298,15 @@ ignore:
- Zubat
```
### How do I use the map??
You can either view the map via opening the html file, or by serving it with SimpleHTTPServer (runs on localhost:8000)
To use SimpleHTTPServer:
You can either view the map via opening the html file, or by serving it with SimpleHTTPServer (runs on localhost:8000)
To use SimpleHTTPServer:
```$ python -m SimpleHTTPServer [port]```
The default port is 8080, you can change that by giving a port number.
Anything above port 1000 does not require root.
You will need to set your username(s) in the userdata.js file before opening:
You will need to set your username(s) in the userdata.js file before opening:
Copy userdata.js.example to userdata.js and edit with your favorite text editor.
put your username in the quotes instead of "username"
If using multiple usernames format like this:
If using multiple usernames format like this:
```var users = ["username1","username2"];```

---------
Expand Down Expand Up @@ -350,7 +342,8 @@ If using multiple usernames format like this:
* riberod07
* th3w4y
* Leaklessgfy

* codybaldwin

-------
## Credits
- [tejado](https://github.com/tejado) many thanks for the API
Expand All @@ -367,5 +360,3 @@ Bitcoin Address: 1PJMCx9NNQRasQYaa4MMff9yyNFffhHgLu
<p align="center">
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WQUXDC54W6EVY"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif"></a>
</p>

[![Analytics](https://ga-beacon.appspot.com/UA-81468120-1/welcome-page-master)](https://github.com/igrigorik/ga-beacon)
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.
Expand Down

0 comments on commit 9556c1a

Please sign in to comment.