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

Revert "Add timeouts to sniper source config" #5631

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 0 additions & 3 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@
{
"enabled": false,
"url": "http://localhost:5000/raw_data",
"timeout": 3,
"key": "pokemons",
"mappings": {
"id": { "param": "pokemon_id" },
Expand All @@ -237,7 +236,6 @@
{
"enabled": false,
"url": "https://pokewatchers.com/grab/",
"timeout": 10,
"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pid" },
Expand All @@ -250,7 +248,6 @@
{
"enabled": false,
"url": "http://pokesnipers.com/api/v1/pokemon.json",
"timeout": 10,
"key": "results",
"mappings": {
"iv": { "param": "iv" },
Expand Down
3 changes: 0 additions & 3 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@
"enabled": false,
"url": "http://localhost:5000/raw_data",
"key": "pokemons",
"timeout": 3,
"mappings": {
"id": { "param": "pokemon_id" },
"name": { "param": "pokemon_name" },
Expand All @@ -491,7 +490,6 @@
{
"enabled": false,
"url": "https://pokewatchers.com/grab/",
"timeout": 10,
"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pid" },
Expand All @@ -504,7 +502,6 @@
{
"enabled": false,
"url": "http://pokesnipers.com/api/v1/pokemon.json",
"timeout": 10,
"key": "results",
"mappings": {
"iv": { "param": "iv" },
Expand Down
12 changes: 2 additions & 10 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
- [Description](#description)
- [Options](#options)
- [Example](#example)
- [Sniping _(Sniper)_](#sniper)
- [Sniping _(Sniper)_](#sniping-_-sniper-_)
- [Description](#description)
- [Options](#options)
- [Example](#example)
Expand Down Expand Up @@ -725,7 +725,7 @@ This task will fetch current pokemon spawns from /raw_data of an PokemonGo-Map i
}
```

## Sniper
## Sniping _(Sniper)_
[[back to top](#table-of-contents)]

### Description
Expand Down Expand Up @@ -754,8 +754,6 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
* `sources.key` - The JSON key that contains the results, eg.: For a JSON response such as `{ "SomeWeirdoName": [{"id": 123, ...}, {"id": 143, ...}]}`, `SomeWeirdoName` would be the key name.
* `sources.url` - The URL that will provide the JSON.
* `sources.enabled` - Defines whether this source is enabled or not. This has nothing to do with the task's `enabled`.
* `sources.timeout` - How long to wait for this source to respond before giving up (default 5 seconds)
* `mappings`- Map JSON parameters to required values.
- `iv` - The JSON param that corresponds to the pokemon IV. Only certain sources provide this info. **NOTE:** `social` mode does not provide this info!
- `id` - The JSON param that corresponds to the pokemon ID. (required)
- `name` - The JSON param that corresponds to the pokemon name. (required)
Expand Down Expand Up @@ -783,8 +781,6 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
"sources": [
{
"url": "http://pokesnipers.com/api/v1/pokemon.json",
"enabled": true,
"timeout": 15,
"key": "results",
"mappings": {
"iv": { "param": "iv" },
Expand All @@ -797,8 +793,6 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
{
"url": "http://localhost:5000/raw_data",
"key": "pokemons",
"enabled": true,
"timeout": 5,
"mappings": {
"id": { "param": "pokemon_id" },
"name": { "param": "pokemon_name" },
Expand All @@ -809,8 +803,6 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
},
{
"url": "https://pokewatchers.com/grab/",
"enabled": true,
"timeout": 15,
"mappings": {
"iv": { "param": "iv" },
"id": { "param": "pid" },
Expand Down
15 changes: 7 additions & 8 deletions pokemongo_bot/cell_workers/sniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ def __init__(self, data):
self.enabled = data.get('enabled', False)
self.time_mask = data.get('time_mask', '%Y-%m-%d %H:%M:%S')
self.mappings = SniperSourceMapping(data.get('mappings', {}))
self.timeout = data.get('timeout', 5)

def __str__(self):
return self.url

def fetch_raw(self):
def fetch_raw(self, timeoutz):
some_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/52.0.2743.116 Safari/537.36'
response = requests.get(self.url, headers={'User-Agent': some_agent}, timeout=self.timeout)
response = requests.get(self.url, headers={'User-Agent': some_agent}, timeout=timeoutz)
results = response.json()

# If the results is a dict, retrieve the list from it by the given key. This will return a list afterall.
return results.get(self.key, []) if isinstance(results, dict) else results

def fetch(self):
def fetch(self, timeout):
pokemons = []

try:
results = self.fetch_raw()
results = self.fetch_raw(timeout)

# Parse results
for result in results:
Expand Down Expand Up @@ -106,8 +105,8 @@ def validate(self):
try:
if self.enabled:
errors = []
data = self.fetch_raw()
data = self.fetch_raw(10)

# Check whether the params really exist if they have been specified like so
if data:
if self.mappings.iv.exists and self.mappings.iv.param not in data[0]:
Expand Down Expand Up @@ -425,7 +424,7 @@ def _get_pokemons_from_url(self):
for source in self.sources:
try:
if source.enabled:
source_pokemons = source.fetch()
source_pokemons = source.fetch(3)
self._trace("Source '{}' returned {} results".format(source.url, len(source_pokemons)))

# Merge lists, making sure to exclude repeated data. Use location as the hash key
Expand Down