本文整理汇总了Python中pgoapi.utilities.f2i方法的典型用法代码示例。如果您正苦于以下问题:Python utilities.f2i方法的具体用法?Python utilities.f2i怎么用?Python utilities.f2i使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgoapi.utilities
的用法示例。
在下文中一共展示了utilities.f2i方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: spin_fort
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def spin_fort(self, fort):
fort_id = fort['id']
latitude = fort['latitude']
longitude = fort['longitude']
request = self.bot.api.create_request()
request.fort_search(
fort_id=fort_id,
fort_latitude=latitude,
fort_longitude=longitude,
player_latitude=f2i(self.bot.position[0]),
player_longitude=f2i(self.bot.position[1])
)
request.call()
self.emit_event(
'spun_fort',
level='debug',
formatted="Spun fort {fort_id}",
data={
'fort_id': fort_id,
'latitude': latitude,
'longitude': longitude
}
)
示例2: get_map_objects
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def get_map_objects(self, lat, lng, timestamp, cellid):
if time.time() - self.last_time_map_object < self.config.map_object_cache_time:
return self.last_map_object
request = self.api.create_request()
request.get_map_objects(
latitude=f2i(lat),
longitude=f2i(lng),
since_timestamp_ms=timestamp,
cell_id=cellid
)
self.last_map_object = request.call()
self.emit_forts_event(self.last_map_object)
#if self.last_map_object:
# print self.last_map_object
self.last_time_map_object = time.time()
return self.last_map_object
示例3: spin_fort
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def spin_fort(self, fort):
fort_id = fort['id']
latitude = fort['latitude']
longitude = fort['longitude']
self.bot.api.fort_search(
fort_id=fort_id,
fort_latitude=latitude,
fort_longitude=longitude,
player_latitude=f2i(self.bot.position[0]),
player_longitude=f2i(self.bot.position[1])
)
self.emit_event(
'spun_fort',
level='debug',
formatted="Spun fort {fort_id}",
data={
'fort_id': fort_id,
'latitude': latitude,
'longitude': longitude
}
)
示例4: get_map_objects
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def get_map_objects(self, lat, lng, timestamp, cellid):
if time.time() - self.last_time_map_object < self.config.map_object_cache_time:
return self.last_map_object
self.last_map_object = self.api.get_map_objects(
latitude=f2i(lat),
longitude=f2i(lng),
since_timestamp_ms=timestamp,
cell_id=cellid
)
self.emit_forts_event(self.last_map_object)
#if self.last_map_object:
# print self.last_map_object
self.last_time_map_object = time.time()
return self.last_map_object
示例5: req_get_map_objects
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def req_get_map_objects(self):
"""Scans current account location."""
# Make sure that we don't hammer with GMO requests
diff = self._last_gmo + self.cfg['scan_delay'] - time.time()
if diff > 0:
time.sleep(diff)
# Jitter if wanted
if self.cfg['jitter_gmo']:
lat, lng = jitter_location(self.latitude, self.longitude)
else:
lat, lng = self.latitude, self.longitude
cell_ids = get_cell_ids(lat, lng)
timestamps = [0, ] * len(cell_ids)
responses = self.perform_request(
lambda req: req.get_map_objects(latitude=f2i(lat),
longitude=f2i(lng),
since_timestamp_ms=timestamps,
cell_id=cell_ids),
get_inbox=True
)
self._last_gmo = self._last_request
return responses
示例6: scan
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def scan(self):
ScanMetrics.NUM_STEPS = len(self.scan_config.COVER)
log.info("Starting scan of {} locations".format(ScanMetrics.NUM_STEPS))
for i, next_pos in enumerate(self.next_position()):
log.debug('Scanning step {:d} of {:d}.'.format(i, ScanMetrics.NUM_STEPS))
log.debug('Scan location is {:f}, {:f}'.format(next_pos[0], next_pos[1]))
# TODO: Add error throttle
cell_ids = get_cell_ids(next_pos[0], next_pos[1], radius=70)
timestamps = [0, ] * len(cell_ids)
self.api.get_map_objects(
latitude=f2i(next_pos[0]),
longitude=f2i(next_pos[1]),
cell_id=cell_ids,
since_timestamp_ms=timestamps,
position=next_pos,
callback=Scanner.callback)
while not self.api.is_work_queue_empty():
# Location change
if self.scan_config.RESTART:
log.info("Restarting scan")
self.api.empty_work_queue()
else:
time.sleep(2)
#self.api.wait_until_done() # Work queue empty != work done
示例7: send_map_request
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def send_map_request(api, position):
try:
api.set_position(*position)
api.get_map_objects(latitude=f2i(position[0]),
longitude=f2i(position[1]),
since_timestamp_ms=TIMESTAMP,
cell_id=get_cellid(position[0], position[1]))
return api.call()
except Exception as e:
log.warn("Uncaught exception when downloading map " + str(e))
return False
示例8: send_map_request
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def send_map_request (self, user, position):
try:
cell_ids = util.get_cell_ids(position[0], position[1])
user._last_call = time.time()
timestamps = [0,] * len(cell_ids)
return user.get_map_objects(
latitude=util.f2i(position[0]),
longitude=util.f2i(position[1]),
since_timestamp_ms=timestamps,
cell_id=cell_ids
)
except ServerSideAccessForbiddenException as e:
logging.info("User {} or IP might be banned, attempting recovery...".format(user._data["username"]))
with self._lock:
now = time.time()
if now - self._last_vpn_retry >= self._delay_between_vpn_retries:
self._last_vpn_retry = now
if self._num_vpn_retries < self._max_vpn_retries_before_switch:
logging.info("Restarting vpn ({} times so far)".format(self._num_vpn_retries))
subprocess.call([self._restart_vpn_file])
self._num_vpn_retries += 1
else:
logging.info("Restarted vpn too many times. Switching to a different vpn now")
subprocess.call([self._switch_vpn_file])
self._num_vpn_retries = 0
# we can hold the lock for a bit during re-auth since there's
# no point in retrying in other threads in the meantime
self.auth_users()
except Exception as e:
logging.info("Uncaught exception when downloading map: {}".format(e))
return False
示例9: find_poi
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def find_poi(api, lat, lng):
poi = {'pokemons': {}, 'forts': []}
step_size = 0.0015
step_limit = 49
coords = generate_spiral(lat, lng, step_size, step_limit)
for coord in coords:
lat = coord['lat']
lng = coord['lng']
api.set_position(lat, lng, 0)
#get_cellid was buggy -> replaced through get_cell_ids from pokecli
#timestamp gets computed a different way:
cell_ids = get_cell_ids(lat, lng)
timestamps = [0,] * len(cell_ids)
response_dict = api.get_map_objects(latitude = util.f2i(lat), longitude = util.f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids)
if (response_dict['responses']):
if 'status' in response_dict['responses']['GET_MAP_OBJECTS']:
if response_dict['responses']['GET_MAP_OBJECTS']['status'] == 1:
for map_cell in response_dict['responses']['GET_MAP_OBJECTS']['map_cells']:
if 'wild_pokemons' in map_cell:
for pokemon in map_cell['wild_pokemons']:
pokekey = get_key_from_pokemon(pokemon)
pokemon['hides_at'] = time.time() + pokemon['time_till_hidden_ms']/1000
poi['pokemons'][pokekey] = pokemon
# time.sleep(0.51)
# new dict, binary data
# print('POI dictionary: \n\r{}'.format(json.dumps(poi, indent=2)))
print('POI dictionary: \n\r{}'.format(pprint.PrettyPrinter(indent=4).pformat(poi)))
print('Open this in a browser to see the path the spiral search took:')
print_gmaps_dbug(coords)
示例10: req_gym_get_info
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def req_gym_get_info(self, gym_id, gym_lat, gym_lng, player_lat, player_lng):
return self.perform_request(
lambda req: req.gym_get_info(gym_id=gym_id,
player_lat_degrees=f2i(player_lat),
player_lng_degrees=f2i(player_lng),
gym_lat_degrees=gym_lat,
gym_lng_degrees=gym_lng))
示例11: scan
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def scan(self):
ScanMetrics.NUM_STEPS = len(self.scan_config.COVER)
log.info("Starting scan of {} locations".format(ScanMetrics.NUM_STEPS))
for i, next_pos in enumerate(self.next_position()):
log.debug('Scanning step {:d} of {:d}.'.format(i, ScanMetrics.NUM_STEPS))
log.debug('Scan location is {:f}, {:f}'.format(next_pos[0], next_pos[1]))
time.sleep(args.delay/1000.0)
# TODO: Add error throttle
cell_ids = get_cell_ids(next_pos[0], next_pos[1], radius=70)
timestamps = [0, ] * len(cell_ids)
self.api.get_map_objects(
latitude=f2i(next_pos[0]),
longitude=f2i(next_pos[1]),
cell_id=cell_ids,
since_timestamp_ms=timestamps,
position=next_pos,
callback=Scanner.callback)
self.api.download_remote_config_version(position=next_pos, platform = 1, app_version = 5500, callback=Scanner.callback2)
while not self.api.is_work_queue_empty():
# Location change
if self.scan_config.RESTART:
log.info("Restarting scan")
self.api.empty_work_queue()
else:
time.sleep(2)
#self.api.wait_until_done() # Work queue empty != work done
示例12: search
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def search(self, position, num_steps):
if self.api._auth_provider and self.api._auth_provider._ticket_expire:
if isinstance(self.api._auth_provider._ticket_expire, (int, long)):
remaining_time = self.api._auth_provider._ticket_expire / 1000.0 - time.time()
if remaining_time > 60:
logger.info("Skipping Pokemon Go login process since already logged in for another {:.2f} seconds".format(remaining_time))
else:
self.login()
else:
logger.warn("skipping login since _ticket_expire was a token.")
else:
self.login()
all_pokemon = {}
num_retries = 0
for step, coord in enumerate(generate_location_steps(position, num_steps, self.visible_range_meters), 1):
lat = coord[0]
lng = coord[1]
self.api.set_position(*coord)
cell_ids = get_cell_ids(lat, lng)
timestamps = [0,] * len(cell_ids)
response_dict = None
while not response_dict:
try:
self.api.get_map_objects(latitude = f2i(lat), longitude = f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids)
response_dict = self.api.call()
except:
logging.warn('exception happened on get_map_objects api call', exc_info=True)
if not response_dict:
if num_retries < MAX_NUM_RETRIES:
num_retries += 1
logger.warn('get_map_objects failed, retrying in %s seconds, %s retries', REQ_SLEEP, num_retries)
time.sleep(REQ_SLEEP)
else:
logger.warn('MAX_NUM_RETRIES exceeded, retrying login...')
self.login()
raise StopIteration
# try:
pokemons = parse_map(response_dict)
# except KeyError as e:
# logger.error('failed to parse map with key error: %s', e)
for key in pokemons.keys():
if not key in all_pokemon:
pokemon = pokemons[key]
all_pokemon[key] = pokemon
yield pokemon
# else:
# logger.info("have duplicate poke: %s", key)
total_steps = (3 * (num_steps**2)) - (3 * num_steps) + 1
logger.info('Completed {:5.2f}% of scan.'.format(float(step) / total_steps * 100))
time.sleep(REQ_SLEEP)
示例13: find_poi
# 需要导入模块: from pgoapi import utilities [as 别名]
# 或者: from pgoapi.utilities import f2i [as 别名]
def find_poi(api, lat, lng, db):
poi = {'pokemons': {}, 'forts': []}
step_size = 0.0015
step_limit = 49
api.set_position(lat, lng, 0)
cell_ids = get_cell_ids(lat, lng)
timestamps = [0,] * len(cell_ids)
while True:
response_dict = api.get_map_objects(latitude = util.f2i(lat), longitude = util.f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids)
if response_dict['status_code'] == 1:
break
if ('PGOAPIRUNNER_DEBUG' in os.environ):
print(response_dict)
if 'status' in response_dict['responses']['GET_MAP_OBJECTS']:
if response_dict['responses']['GET_MAP_OBJECTS']['status'] == 1:
for map_cell in response_dict['responses']['GET_MAP_OBJECTS']['map_cells']:
if 'wild_pokemons' in map_cell:
if ('PGOAPIRUNNER_DEBUG' in os.environ):
print('Pokemans:\n')
print(len(map_cell['wild_pokemons']))
for pokemon in map_cell['wild_pokemons']:
pokekey = get_key_from_pokemon(pokemon)
pokemon['hides_at'] = time.time() + pokemon['time_till_hidden_ms']/1000
pokemon['location'] = {'type': 'Point', 'coordinates': [float(pokemon['latitude']), float(pokemon['longitude'])]}
pokemon['pokekey'] = pokekey
del pokemon["last_modified_timestamp_ms"]
del pokemon["longitude"]
del pokemon["latitude"]
del pokemon["encounter_id"]
del pokemon["time_till_hidden_ms"]
if db.pokemon.find({"pokekey": pokekey}, {"_id": 1}).limit(1).count() == 0:
db.pokemon.insert(pokemon)
poi['pokemons'][pokekey] = pokemon
else:
if ('PGOAPIRUNNER_DEBUG' in os.environ):
print("no pokemon? nearby")
print(map_cell)
else:
if ('PGOAPIRUNNER_DEBUG' in os.environ):
tmpl = string.Template("Error, status code: $status")
print(tmpl.substitute(status=response_dict['responses']['GET_MAP_OBJECTS']['status']))
print( format(str(lat) + " " + str(lng) + " complete" ) )
if ('PGOAPIRUNNER_DEBUG' in os.environ):
print( poi )
return poi