| 33 | return self.url |
| 34 | |
| 35 | def fetch_raw(self): |
| 36 | some_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/52.0.2743.116 Safari/537.36' |
| 37 | response = requests.get(self.url, headers={'User-Agent': some_agent}, timeout=self.timeout) |
| 38 | |
| 39 | results = response.json() |
| 40 | |
| 41 | # If the results is a dict, retrieve the list from it by the given key. This will return a list afterall. |
| 42 | if isinstance(results, dict): |
| 43 | results = results.get(self.key, []) |
| 44 | |
| 45 | # If results is STILL a dict (eg. each pokemon is its own dict), need to build data from nested json (example whereispokemon.net) |
| 46 | while isinstance(results,dict): |
| 47 | tmpResults = [] |
| 48 | for key, value in results.iteritems(): |
| 49 | tmpResults.append(value) |
| 50 | results = tmpResults |
| 51 | |
| 52 | return results |
| 53 | |
| 54 | def fetch(self): |
| 55 | pokemons = [] |