MCPcopy
hub / github.com/PokemonGoF/PokemonGo-Bot / fetch

Method fetch

pokemongo_bot/cell_workers/sniper.py:54–126  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

52 return results
53
54 def fetch(self):
55 pokemons = []
56
57 try:
58 results = self.fetch_raw()
59
60 # Parse results
61 for result in results:
62 iv = result.get(self.mappings.iv.param)
63 id = result.get(self.mappings.id.param)
64 name = self._get_closest_name(self._fixname(result.get(self.mappings.name.param)))
65 latitude = result.get(self.mappings.latitude.param)
66 longitude = result.get(self.mappings.longitude.param)
67 expiration = result.get(self.mappings.expiration.param)
68 encounter = result.get(self.mappings.encounter.param)
69 spawnpoint = result.get(self.mappings.spawnpoint.param)
70
71 # If this is a composite param, split it ("coords": "-31.415553, -64.190480")
72 if self.mappings.latitude.param == self.mappings.longitude.param:
73 position = result.get(self.mappings.latitude.param).replace(" ", "").split(",")
74 latitude = position[0]
75 longitude = position[1]
76
77 # Some sources block access to all pokemon, need to skip those!
78 try:
79 float(latitude)
80 float(longitude)
81 except ValueError:
82 # Seems to be blacked out, do next.
83 continue
84
85 # Format the time accordingly. Pokemon times are in milliseconds!
86 if self.mappings.expiration.exists and expiration:
87 if self.mappings.expiration.format == SniperSourceMappingTimeFormat.SECONDS:
88 expiration = expiration * 1000
89 elif self.mappings.expiration.format == SniperSourceMappingTimeFormat.UTC:
90 utc_date = datetime.strptime(expiration.replace("T", " ")[:19], self.time_mask)
91 unix_timestamp = calendar.timegm(utc_date.timetuple())
92 local_date = datetime.fromtimestamp(unix_timestamp)
93 local_date = local_date.replace(microsecond=utc_date.microsecond)
94 expiration = time.mktime(local_date.timetuple()) * 1000
95 else:
96 minutes_to_expire = 3
97 seconds_per_minute = 60
98 expiration = (time.time() + minutes_to_expire * seconds_per_minute) * 1000
99
100 # If either name or ID are invalid, fix it using each other
101 if not name or not id:
102 if not name and id:
103 name = Pokemons.name_for(id)
104 if not id and name:
105 id = Pokemons.id_for(name)
106
107 # Some type castings were specified for a better readability
108 pokemons.append({
109 'iv': float(iv or 0),
110 'pokemon_id': int(id or 0),
111 'pokemon_name': str(name or ''),

Callers 1

Calls 6

fetch_rawMethod · 0.95
_get_closest_nameMethod · 0.95
_fixnameMethod · 0.95
id_forMethod · 0.80
getMethod · 0.45
name_forMethod · 0.45

Tested by

no test coverage detected