We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Issue] donot_evolve_list not obeyed
### Expected Behavior

In my config.json, i have mentioned not to evolve dratini. So the bot should not evolve dratini.
### Actual Behavior

bot evolved dratini.
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->
### Output when issue occurred

[2016-09-01 05:34:16] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Dratini [IV 0.91] [CP 552] [2 candies] [+1000 xp]
[2016-09-01 05:34:37] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.6] [CP 589] [63 candies] [+500 xp]
[2016-09-01 05:35:06] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.89] [CP 583] [39 candies] [+500 xp]
[2016-09-01 05:35:34] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Tentacool [IV 0.53] [CP 605] [1 candies] [+500 xp]
[2016-09-01 05:36:07] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.93] [CP 627] [63 candies] [+500 xp]
[2016-09-01 05:36:30] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.73] [CP 597] [39 candies] [+500 xp]
[2016-09-01 05:37:05] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Machop [IV 0.62] [CP 779] [60 candies] [+500 xp]
### Steps to Reproduce

Use latest master bot with latest config.json
### Other Information

OS: 
Win 10
Branch: 
Master
Git Commit: 
42d670a411b4f8dc9a6206dd10a88cc51744026d
Python Version: 
2.3.6

[Issue] donot_evolve_list not obeyed
### Expected Behavior

In my config.json, i have mentioned not to evolve dratini. So the bot should not evolve dratini.
### Actual Behavior

bot evolved dratini.
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->
### Output when issue occurred

[2016-09-01 05:34:16] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Dratini [IV 0.91] [CP 552] [2 candies] [+1000 xp]
[2016-09-01 05:34:37] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.6] [CP 589] [63 candies] [+500 xp]
[2016-09-01 05:35:06] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.89] [CP 583] [39 candies] [+500 xp]
[2016-09-01 05:35:34] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Tentacool [IV 0.53] [CP 605] [1 candies] [+500 xp]
[2016-09-01 05:36:07] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.93] [CP 627] [63 candies] [+500 xp]
[2016-09-01 05:36:30] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.73] [CP 597] [39 candies] [+500 xp]
[2016-09-01 05:37:05] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Machop [IV 0.62] [CP 779] [60 candies] [+500 xp]
### Steps to Reproduce

Use latest master bot with latest config.json
### Other Information

OS: 
Win 10
Branch: 
Master
Git Commit: 
42d670a411b4f8dc9a6206dd10a88cc51744026d
Python Version: 
2.3.6


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pokemongo_bot/cell_workers/evolve_pokemon.py`
Content:
```
1 from random import uniform
2 
3 from pokemongo_bot import inventory
4 from pokemongo_bot.human_behaviour import sleep
5 from pokemongo_bot.inventory import Pokemon
6 from pokemongo_bot.item_list import Item
7 from pokemongo_bot.base_task import BaseTask
8 from pokemongo_bot.datastore import Datastore
9 
10 
11 class EvolvePokemon(Datastore, BaseTask):
12     SUPPORTED_TASK_API_VERSION = 1
13     def __init__(self, bot, config):
14         super(EvolvePokemon, self).__init__(bot, config)
15 
16     def initialize(self):
17         self.api = self.bot.api
18         self.evolve_list = self.config.get('evolve_list', [])
19         self.donot_evolve_list = self.config.get('donot_evolve_list', [])
20         self.min_evolve_speed = self.config.get('min_evolve_speed', 25)
21         self.max_evolve_speed = self.config.get('max_evolve_speed', 30)
22         self.first_evolve_by = self.config.get('first_evolve_by', 'cp')
23         self.evolve_above_cp = self.config.get('evolve_above_cp', 500)
24         self.evolve_above_iv = self.config.get('evolve_above_iv', 0.8)
25         self.cp_iv_logic = self.config.get('logic', 'or')
26         self.use_lucky_egg = self.config.get('use_lucky_egg', False)
27         self._validate_config()
28 
29     def _validate_config(self):
30         if isinstance(self.evolve_list, basestring):
31             self.evolve_list = [str(pokemon_name).strip() for pokemon_name in self.evolve_list.split(',')]
32             
33         if isinstance(self.donot_evolve_list, basestring):
34             self.donot_evolve_list = [str(pokemon_name).strip() for pokemon_name in self.donot_evolve_list.split(',')]
35 
36         if 'evolve_speed' in self.config:
37             self.logger.warning("evolve_speed is deprecated, instead please use 'min_evolve_speed' and 'max_evolved_speed'.")
38 
39         if 'evolve_all' in self.config:
40             self.logger.warning("evolve_all is deprecated, instead please use 'evolve_list' and 'donot_evolve_list'.")
41 
42     def work(self):
43         if not self._should_run():
44             return
45 
46         filtered_list = self._sort_and_filter()
47 
48         if (len(self.evolve_list) > 0) and self.evolve_list[0] != 'all':
49             filtered_list = filter(lambda x: x.name in self.evolve_list, filtered_list)
50 
51         if (len(self.donot_evolve_list) > 0) and self.donot_evolve_list[0] != 'none':
52             filtered_list = filter(lambda pokemon: pokemon.name not in self.donot_evolve_list, filtered_list)
53 
54         cache = {}
55         for pokemon in filtered_list:
56             if pokemon.can_evolve_now():
57                 self._execute_pokemon_evolve(pokemon, cache)
58 
59     def _should_run(self):
60         if not self.evolve_list or self.evolve_list[0] == 'none':
61             return False
62 
63         # Evolve all is used - Use Lucky egg only at the first tick
64         if self.bot.tick_count is not 1 or not self.use_lucky_egg:
65             return True
66 
67         lucky_egg = inventory.items().get(Item.ITEM_LUCKY_EGG.value)
68 
69         # Make sure the user has a lucky egg and skip if not
70         if lucky_egg.count > 0:
71             response_dict_lucky_egg = self.bot.use_lucky_egg()
72             if response_dict_lucky_egg:
73                 result = response_dict_lucky_egg.get('responses', {}).get('USE_ITEM_XP_BOOST', {}).get('result', 0)
74                 if result is 1:  # Request success
75                     lucky_egg.remove(1)
76                     self.emit_event(
77                         'used_lucky_egg',
78                         formatted='Used lucky egg ({amount_left} left).',
79                         data={
80                              'amount_left': lucky_egg.count
81                         }
82                     )
83                     return True
84                 else:
85                     self.emit_event(
86                         'lucky_egg_error',
87                         level='error',
88                         formatted='Failed to use lucky egg!'
89                     )
90                     return False
91         else:
92             # Skipping evolve so they aren't wasted
93             self.emit_event(
94                 'skip_evolve',
95                 formatted='Skipping evolve because has no lucky egg.'
96             )
97             return False
98 
99     def _sort_and_filter(self):
100         pokemons = []
101         logic_to_function = {
102             'or': lambda pokemon: pokemon.cp >= self.evolve_above_cp or pokemon.iv >= self.evolve_above_iv,
103             'and': lambda pokemon: pokemon.cp >= self.evolve_above_cp and pokemon.iv >= self.evolve_above_iv
104         }
105 
106         for pokemon in inventory.pokemons().all():
107             if pokemon.unique_id > 0 and pokemon.has_next_evolution() and (logic_to_function[self.cp_iv_logic](pokemon)):
108                 pokemons.append(pokemon)
109 
110         if self.first_evolve_by == "cp":
111             pokemons.sort(key=lambda x: (x.pokemon_id, x.cp, x.iv), reverse=True)
112         else:
113             pokemons.sort(key=lambda x: (x.pokemon_id, x.iv, x.cp), reverse=True)
114 
115         return pokemons
116 
117     def _execute_pokemon_evolve(self, pokemon, cache):
118         if pokemon.name in cache:
119             return False
120 
121         response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
122         if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:
123             xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
124             evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})
125             awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)
126             candy = inventory.candies().get(pokemon.pokemon_id)
127 
128             candy.consume(pokemon.evolution_cost - awarded_candies)
129 
130             self.emit_event(
131                 'pokemon_evolved',
132                 formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [+{xp} xp]",
133                 data={
134                     'pokemon': pokemon.name,
135                     'iv': pokemon.iv,
136                     'cp': pokemon.cp,
137                     'candy': candy.quantity,
138                     'xp': xp,
139                 }
140             )
141 
142             inventory.pokemons().remove(pokemon.unique_id)
143             new_pokemon = inventory.Pokemon(evolution)
144             inventory.pokemons().add(new_pokemon)
145             inventory.player().exp += xp
146 
147             sleep(uniform(self.min_evolve_speed, self.max_evolve_speed))
148             evolve_result = True
149         else:
150             # cache pokemons we can't evolve. Less server calls
151             cache[pokemon.name] = 1
152             sleep(0.7)
153             evolve_result = False
154 
155         with self.bot.database as conn:
156             c = conn.cursor()
157             c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'")
158 
159         result = c.fetchone()
160 
161         while True:
162             if result[0] == 1:
163                 conn.execute('''INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))
164                 break
165             else:
166                 self.emit_event(
167                     'evolve_log',
168                     sender=self,
169                     level='info',
170                     formatted="evolve_log table not found, skipping log"
171                 )
172                 break
173 
174         return evolve_result
175
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py
--- a/pokemongo_bot/cell_workers/evolve_pokemon.py
+++ b/pokemongo_bot/cell_workers/evolve_pokemon.py
@@ -28,10 +28,10 @@
 
     def _validate_config(self):
         if isinstance(self.evolve_list, basestring):
-            self.evolve_list = [str(pokemon_name).strip() for pokemon_name in self.evolve_list.split(',')]
+            self.evolve_list = [str(pokemon_name).strip().lower() for pokemon_name in self.evolve_list.split(',')]
             
         if isinstance(self.donot_evolve_list, basestring):
-            self.donot_evolve_list = [str(pokemon_name).strip() for pokemon_name in self.donot_evolve_list.split(',')]
+            self.donot_evolve_list = [str(pokemon_name).strip().lower() for pokemon_name in self.donot_evolve_list.split(',')]
 
         if 'evolve_speed' in self.config:
             self.logger.warning("evolve_speed is deprecated, instead please use 'min_evolve_speed' and 'max_evolved_speed'.")
@@ -46,10 +46,10 @@
         filtered_list = self._sort_and_filter()
 
         if (len(self.evolve_list) > 0) and self.evolve_list[0] != 'all':
-            filtered_list = filter(lambda x: x.name in self.evolve_list, filtered_list)
+            filtered_list = filter(lambda x: x.name.lower() in self.evolve_list, filtered_list)
 
         if (len(self.donot_evolve_list) > 0) and self.donot_evolve_list[0] != 'none':
-            filtered_list = filter(lambda pokemon: pokemon.name not in self.donot_evolve_list, filtered_list)
+            filtered_list = filter(lambda pokemon: pokemon.name.lower() not in self.donot_evolve_list, filtered_list)
 
         cache = {}
         for pokemon in filtered_list:

{"golden_diff": "diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py\n--- a/pokemongo_bot/cell_workers/evolve_pokemon.py\n+++ b/pokemongo_bot/cell_workers/evolve_pokemon.py\n@@ -28,10 +28,10 @@\n \n     def _validate_config(self):\n         if isinstance(self.evolve_list, basestring):\n-            self.evolve_list = [str(pokemon_name).strip() for pokemon_name in self.evolve_list.split(',')]\n+            self.evolve_list = [str(pokemon_name).strip().lower() for pokemon_name in self.evolve_list.split(',')]\n             \n         if isinstance(self.donot_evolve_list, basestring):\n-            self.donot_evolve_list = [str(pokemon_name).strip() for pokemon_name in self.donot_evolve_list.split(',')]\n+            self.donot_evolve_list = [str(pokemon_name).strip().lower() for pokemon_name in self.donot_evolve_list.split(',')]\n \n         if 'evolve_speed' in self.config:\n             self.logger.warning(\"evolve_speed is deprecated, instead please use 'min_evolve_speed' and 'max_evolved_speed'.\")\n@@ -46,10 +46,10 @@\n         filtered_list = self._sort_and_filter()\n \n         if (len(self.evolve_list) > 0) and self.evolve_list[0] != 'all':\n-            filtered_list = filter(lambda x: x.name in self.evolve_list, filtered_list)\n+            filtered_list = filter(lambda x: x.name.lower() in self.evolve_list, filtered_list)\n \n         if (len(self.donot_evolve_list) > 0) and self.donot_evolve_list[0] != 'none':\n-            filtered_list = filter(lambda pokemon: pokemon.name not in self.donot_evolve_list, filtered_list)\n+            filtered_list = filter(lambda pokemon: pokemon.name.lower() not in self.donot_evolve_list, filtered_list)\n \n         cache = {}\n         for pokemon in filtered_list:\n", "issue": "[Issue] donot_evolve_list not obeyed\n### Expected Behavior\n\nIn my config.json, i have mentioned not to evolve dratini. So the bot should not evolve dratini.\n### Actual Behavior\n\nbot evolved dratini.\n### Your FULL config.json (remove your username, password, gmapkey and any other private info)\n\n<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->\n### Output when issue occurred\n\n[2016-09-01 05:34:16] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Dratini [IV 0.91] [CP 552] [2 candies] [+1000 xp]\n[2016-09-01 05:34:37] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.6] [CP 589] [63 candies] [+500 xp]\n[2016-09-01 05:35:06] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.89] [CP 583] [39 candies] [+500 xp]\n[2016-09-01 05:35:34] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Tentacool [IV 0.53] [CP 605] [1 candies] [+500 xp]\n[2016-09-01 05:36:07] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.93] [CP 627] [63 candies] [+500 xp]\n[2016-09-01 05:36:30] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.73] [CP 597] [39 candies] [+500 xp]\n[2016-09-01 05:37:05] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Machop [IV 0.62] [CP 779] [60 candies] [+500 xp]\n### Steps to Reproduce\n\nUse latest master bot with latest config.json\n### Other Information\n\nOS: \nWin 10\nBranch: \nMaster\nGit Commit: \n42d670a411b4f8dc9a6206dd10a88cc51744026d\nPython Version: \n2.3.6\n\n[Issue] donot_evolve_list not obeyed\n### Expected Behavior\n\nIn my config.json, i have mentioned not to evolve dratini. So the bot should not evolve dratini.\n### Actual Behavior\n\nbot evolved dratini.\n### Your FULL config.json (remove your username, password, gmapkey and any other private info)\n\n<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->\n### Output when issue occurred\n\n[2016-09-01 05:34:16] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Dratini [IV 0.91] [CP 552] [2 candies] [+1000 xp]\n[2016-09-01 05:34:37] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.6] [CP 589] [63 candies] [+500 xp]\n[2016-09-01 05:35:06] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Geodude [IV 0.89] [CP 583] [39 candies] [+500 xp]\n[2016-09-01 05:35:34] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Tentacool [IV 0.53] [CP 605] [1 candies] [+500 xp]\n[2016-09-01 05:36:07] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.93] [CP 627] [63 candies] [+500 xp]\n[2016-09-01 05:36:30] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Bellsprout [IV 0.73] [CP 597] [39 candies] [+500 xp]\n[2016-09-01 05:37:05] [EvolvePokemon] [INFO] [pokemon_evolved] Evolved Machop [IV 0.62] [CP 779] [60 candies] [+500 xp]\n### Steps to Reproduce\n\nUse latest master bot with latest config.json\n### Other Information\n\nOS: \nWin 10\nBranch: \nMaster\nGit Commit: \n42d670a411b4f8dc9a6206dd10a88cc51744026d\nPython Version: \n2.3.6\n\n", "before_files": [{"content": "from random import uniform\n\nfrom pokemongo_bot import inventory\nfrom pokemongo_bot.human_behaviour import sleep\nfrom pokemongo_bot.inventory import Pokemon\nfrom pokemongo_bot.item_list import Item\nfrom pokemongo_bot.base_task import BaseTask\nfrom pokemongo_bot.datastore import Datastore\n\n\nclass EvolvePokemon(Datastore, BaseTask):\n    SUPPORTED_TASK_API_VERSION = 1\n    def __init__(self, bot, config):\n        super(EvolvePokemon, self).__init__(bot, config)\n\n    def initialize(self):\n        self.api = self.bot.api\n        self.evolve_list = self.config.get('evolve_list', [])\n        self.donot_evolve_list = self.config.get('donot_evolve_list', [])\n        self.min_evolve_speed = self.config.get('min_evolve_speed', 25)\n        self.max_evolve_speed = self.config.get('max_evolve_speed', 30)\n        self.first_evolve_by = self.config.get('first_evolve_by', 'cp')\n        self.evolve_above_cp = self.config.get('evolve_above_cp', 500)\n        self.evolve_above_iv = self.config.get('evolve_above_iv', 0.8)\n        self.cp_iv_logic = self.config.get('logic', 'or')\n        self.use_lucky_egg = self.config.get('use_lucky_egg', False)\n        self._validate_config()\n\n    def _validate_config(self):\n        if isinstance(self.evolve_list, basestring):\n            self.evolve_list = [str(pokemon_name).strip() for pokemon_name in self.evolve_list.split(',')]\n            \n        if isinstance(self.donot_evolve_list, basestring):\n            self.donot_evolve_list = [str(pokemon_name).strip() for pokemon_name in self.donot_evolve_list.split(',')]\n\n        if 'evolve_speed' in self.config:\n            self.logger.warning(\"evolve_speed is deprecated, instead please use 'min_evolve_speed' and 'max_evolved_speed'.\")\n\n        if 'evolve_all' in self.config:\n            self.logger.warning(\"evolve_all is deprecated, instead please use 'evolve_list' and 'donot_evolve_list'.\")\n\n    def work(self):\n        if not self._should_run():\n            return\n\n        filtered_list = self._sort_and_filter()\n\n        if (len(self.evolve_list) > 0) and self.evolve_list[0] != 'all':\n            filtered_list = filter(lambda x: x.name in self.evolve_list, filtered_list)\n\n        if (len(self.donot_evolve_list) > 0) and self.donot_evolve_list[0] != 'none':\n            filtered_list = filter(lambda pokemon: pokemon.name not in self.donot_evolve_list, filtered_list)\n\n        cache = {}\n        for pokemon in filtered_list:\n            if pokemon.can_evolve_now():\n                self._execute_pokemon_evolve(pokemon, cache)\n\n    def _should_run(self):\n        if not self.evolve_list or self.evolve_list[0] == 'none':\n            return False\n\n        # Evolve all is used - Use Lucky egg only at the first tick\n        if self.bot.tick_count is not 1 or not self.use_lucky_egg:\n            return True\n\n        lucky_egg = inventory.items().get(Item.ITEM_LUCKY_EGG.value)\n\n        # Make sure the user has a lucky egg and skip if not\n        if lucky_egg.count > 0:\n            response_dict_lucky_egg = self.bot.use_lucky_egg()\n            if response_dict_lucky_egg:\n                result = response_dict_lucky_egg.get('responses', {}).get('USE_ITEM_XP_BOOST', {}).get('result', 0)\n                if result is 1:  # Request success\n                    lucky_egg.remove(1)\n                    self.emit_event(\n                        'used_lucky_egg',\n                        formatted='Used lucky egg ({amount_left} left).',\n                        data={\n                             'amount_left': lucky_egg.count\n                        }\n                    )\n                    return True\n                else:\n                    self.emit_event(\n                        'lucky_egg_error',\n                        level='error',\n                        formatted='Failed to use lucky egg!'\n                    )\n                    return False\n        else:\n            # Skipping evolve so they aren't wasted\n            self.emit_event(\n                'skip_evolve',\n                formatted='Skipping evolve because has no lucky egg.'\n            )\n            return False\n\n    def _sort_and_filter(self):\n        pokemons = []\n        logic_to_function = {\n            'or': lambda pokemon: pokemon.cp >= self.evolve_above_cp or pokemon.iv >= self.evolve_above_iv,\n            'and': lambda pokemon: pokemon.cp >= self.evolve_above_cp and pokemon.iv >= self.evolve_above_iv\n        }\n\n        for pokemon in inventory.pokemons().all():\n            if pokemon.unique_id > 0 and pokemon.has_next_evolution() and (logic_to_function[self.cp_iv_logic](pokemon)):\n                pokemons.append(pokemon)\n\n        if self.first_evolve_by == \"cp\":\n            pokemons.sort(key=lambda x: (x.pokemon_id, x.cp, x.iv), reverse=True)\n        else:\n            pokemons.sort(key=lambda x: (x.pokemon_id, x.iv, x.cp), reverse=True)\n\n        return pokemons\n\n    def _execute_pokemon_evolve(self, pokemon, cache):\n        if pokemon.name in cache:\n            return False\n\n        response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.unique_id)\n        if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:\n            xp = response_dict.get(\"responses\", {}).get(\"EVOLVE_POKEMON\", {}).get(\"experience_awarded\", 0)\n            evolution = response_dict.get(\"responses\", {}).get(\"EVOLVE_POKEMON\", {}).get(\"evolved_pokemon_data\", {})\n            awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)\n            candy = inventory.candies().get(pokemon.pokemon_id)\n\n            candy.consume(pokemon.evolution_cost - awarded_candies)\n\n            self.emit_event(\n                'pokemon_evolved',\n                formatted=\"Evolved {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [+{xp} xp]\",\n                data={\n                    'pokemon': pokemon.name,\n                    'iv': pokemon.iv,\n                    'cp': pokemon.cp,\n                    'candy': candy.quantity,\n                    'xp': xp,\n                }\n            )\n\n            inventory.pokemons().remove(pokemon.unique_id)\n            new_pokemon = inventory.Pokemon(evolution)\n            inventory.pokemons().add(new_pokemon)\n            inventory.player().exp += xp\n\n            sleep(uniform(self.min_evolve_speed, self.max_evolve_speed))\n            evolve_result = True\n        else:\n            # cache pokemons we can't evolve. Less server calls\n            cache[pokemon.name] = 1\n            sleep(0.7)\n            evolve_result = False\n\n        with self.bot.database as conn:\n            c = conn.cursor()\n            c.execute(\"SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'\")\n\n        result = c.fetchone()\n\n        while True:\n            if result[0] == 1:\n                conn.execute('''INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))\n                break\n            else:\n                self.emit_event(\n                    'evolve_log',\n                    sender=self,\n                    level='info',\n                    formatted=\"evolve_log table not found, skipping log\"\n                )\n                break\n\n        return evolve_result\n", "path": "pokemongo_bot/cell_workers/evolve_pokemon.py"}], "after_files": [{"content": "from random import uniform\n\nfrom pokemongo_bot import inventory\nfrom pokemongo_bot.human_behaviour import sleep\nfrom pokemongo_bot.inventory import Pokemon\nfrom pokemongo_bot.item_list import Item\nfrom pokemongo_bot.base_task import BaseTask\nfrom pokemongo_bot.datastore import Datastore\n\n\nclass EvolvePokemon(Datastore, BaseTask):\n    SUPPORTED_TASK_API_VERSION = 1\n    def __init__(self, bot, config):\n        super(EvolvePokemon, self).__init__(bot, config)\n\n    def initialize(self):\n        self.api = self.bot.api\n        self.evolve_list = self.config.get('evolve_list', [])\n        self.donot_evolve_list = self.config.get('donot_evolve_list', [])\n        self.min_evolve_speed = self.config.get('min_evolve_speed', 25)\n        self.max_evolve_speed = self.config.get('max_evolve_speed', 30)\n        self.first_evolve_by = self.config.get('first_evolve_by', 'cp')\n        self.evolve_above_cp = self.config.get('evolve_above_cp', 500)\n        self.evolve_above_iv = self.config.get('evolve_above_iv', 0.8)\n        self.cp_iv_logic = self.config.get('logic', 'or')\n        self.use_lucky_egg = self.config.get('use_lucky_egg', False)\n        self._validate_config()\n\n    def _validate_config(self):\n        if isinstance(self.evolve_list, basestring):\n            self.evolve_list = [str(pokemon_name).strip().lower() for pokemon_name in self.evolve_list.split(',')]\n            \n        if isinstance(self.donot_evolve_list, basestring):\n            self.donot_evolve_list = [str(pokemon_name).strip().lower() for pokemon_name in self.donot_evolve_list.split(',')]\n\n        if 'evolve_speed' in self.config:\n            self.logger.warning(\"evolve_speed is deprecated, instead please use 'min_evolve_speed' and 'max_evolved_speed'.\")\n\n        if 'evolve_all' in self.config:\n            self.logger.warning(\"evolve_all is deprecated, instead please use 'evolve_list' and 'donot_evolve_list'.\")\n\n    def work(self):\n        if not self._should_run():\n            return\n\n        filtered_list = self._sort_and_filter()\n\n        if (len(self.evolve_list) > 0) and self.evolve_list[0] != 'all':\n            filtered_list = filter(lambda x: x.name.lower() in self.evolve_list, filtered_list)\n\n        if (len(self.donot_evolve_list) > 0) and self.donot_evolve_list[0] != 'none':\n            filtered_list = filter(lambda pokemon: pokemon.name.lower() not in self.donot_evolve_list, filtered_list)\n\n        cache = {}\n        for pokemon in filtered_list:\n            if pokemon.can_evolve_now():\n                self._execute_pokemon_evolve(pokemon, cache)\n\n    def _should_run(self):\n        if not self.evolve_list or self.evolve_list[0] == 'none':\n            return False\n\n        # Evolve all is used - Use Lucky egg only at the first tick\n        if self.bot.tick_count is not 1 or not self.use_lucky_egg:\n            return True\n\n        lucky_egg = inventory.items().get(Item.ITEM_LUCKY_EGG.value)\n\n        # Make sure the user has a lucky egg and skip if not\n        if lucky_egg.count > 0:\n            response_dict_lucky_egg = self.bot.use_lucky_egg()\n            if response_dict_lucky_egg:\n                result = response_dict_lucky_egg.get('responses', {}).get('USE_ITEM_XP_BOOST', {}).get('result', 0)\n                if result is 1:  # Request success\n                    lucky_egg.remove(1)\n                    self.emit_event(\n                        'used_lucky_egg',\n                        formatted='Used lucky egg ({amount_left} left).',\n                        data={\n                             'amount_left': lucky_egg.count\n                        }\n                    )\n                    return True\n                else:\n                    self.emit_event(\n                        'lucky_egg_error',\n                        level='error',\n                        formatted='Failed to use lucky egg!'\n                    )\n                    return False\n        else:\n            # Skipping evolve so they aren't wasted\n            self.emit_event(\n                'skip_evolve',\n                formatted='Skipping evolve because has no lucky egg.'\n            )\n            return False\n\n    def _sort_and_filter(self):\n        pokemons = []\n        logic_to_function = {\n            'or': lambda pokemon: pokemon.cp >= self.evolve_above_cp or pokemon.iv >= self.evolve_above_iv,\n            'and': lambda pokemon: pokemon.cp >= self.evolve_above_cp and pokemon.iv >= self.evolve_above_iv\n        }\n\n        for pokemon in inventory.pokemons().all():\n            if pokemon.unique_id > 0 and pokemon.has_next_evolution() and (logic_to_function[self.cp_iv_logic](pokemon)):\n                pokemons.append(pokemon)\n\n        if self.first_evolve_by == \"cp\":\n            pokemons.sort(key=lambda x: (x.pokemon_id, x.cp, x.iv), reverse=True)\n        else:\n            pokemons.sort(key=lambda x: (x.pokemon_id, x.iv, x.cp), reverse=True)\n\n        return pokemons\n\n    def _execute_pokemon_evolve(self, pokemon, cache):\n        if pokemon.name in cache:\n            return False\n\n        response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.unique_id)\n        if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:\n            xp = response_dict.get(\"responses\", {}).get(\"EVOLVE_POKEMON\", {}).get(\"experience_awarded\", 0)\n            evolution = response_dict.get(\"responses\", {}).get(\"EVOLVE_POKEMON\", {}).get(\"evolved_pokemon_data\", {})\n            awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)\n            candy = inventory.candies().get(pokemon.pokemon_id)\n\n            candy.consume(pokemon.evolution_cost - awarded_candies)\n\n            self.emit_event(\n                'pokemon_evolved',\n                formatted=\"Evolved {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [+{xp} xp]\",\n                data={\n                    'pokemon': pokemon.name,\n                    'iv': pokemon.iv,\n                    'cp': pokemon.cp,\n                    'candy': candy.quantity,\n                    'xp': xp,\n                }\n            )\n\n            inventory.pokemons().remove(pokemon.unique_id)\n            new_pokemon = inventory.Pokemon(evolution)\n            inventory.pokemons().add(new_pokemon)\n            inventory.player().exp += xp\n\n            sleep(uniform(self.min_evolve_speed, self.max_evolve_speed))\n            evolve_result = True\n        else:\n            # cache pokemons we can't evolve. Less server calls\n            cache[pokemon.name] = 1\n            sleep(0.7)\n            evolve_result = False\n\n        with self.bot.database as conn:\n            c = conn.cursor()\n            c.execute(\"SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'\")\n\n        result = c.fetchone()\n\n        while True:\n            if result[0] == 1:\n                conn.execute('''INSERT INTO evolve_log (pokemon, iv, cp) VALUES (?, ?, ?)''', (pokemon.name, pokemon.iv, pokemon.cp))\n                break\n            else:\n                self.emit_event(\n                    'evolve_log',\n                    sender=self,\n                    level='info',\n                    formatted=\"evolve_log table not found, skipping log\"\n                )\n                break\n\n        return evolve_result\n", "path": "pokemongo_bot/cell_workers/evolve_pokemon.py"}]}