本文整理汇总了Python中pokemongo_bot.socketio_server.runner.SocketIoRunner.start_listening_async方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIoRunner.start_listening_async方法的具体用法?Python SocketIoRunner.start_listening_async怎么用?Python SocketIoRunner.start_listening_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pokemongo_bot.socketio_server.runner.SocketIoRunner
的用法示例。
在下文中一共展示了SocketIoRunner.start_listening_async方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PokemonGoBot
# 需要导入模块: from pokemongo_bot.socketio_server.runner import SocketIoRunner [as 别名]
# 或者: from pokemongo_bot.socketio_server.runner.SocketIoRunner import start_listening_async [as 别名]
class PokemonGoBot(object):
@property
def position(self):
return self.api._position_lat, self.api._position_lng, 0
def __init__(self, config):
self.config = config
self.fort_timeouts = dict()
self.pokemon_list = json.load(
open(os.path.join('data', 'pokemon.json'))
)
self.item_list = json.load(open(os.path.join('data', 'items.json')))
self.metrics = Metrics(self)
self.latest_inventory = None
self.cell = None
self.recent_forts = [None] * config.forts_max_circle_size
self.tick_count = 0
self.softban = False
self.start_position = None
self.last_map_object = None
self.last_time_map_object = 0
# Make our own copy of the workers for this instance
self.workers = []
def start(self):
self._setup_logging()
self._setup_api()
random.seed()
def _setup_event_system(self):
handlers = [LoggingHandler()]
if self.config.websocket_server:
websocket_handler = SocketIoHandler(self.config.websocket_server_url)
handlers.append(websocket_handler)
if self.config.websocket_start_embedded_server:
self.sio_runner = SocketIoRunner(self.config.websocket_server_url)
self.sio_runner.start_listening_async()
self.event_manager = EventManager(*handlers)
# Registering event:
# self.event_manager.register_event("location", parameters=['lat', 'lng'])
#
# Emitting event should be enough to add logging and send websocket
# message: :
# self.event_manager.emit('location', 'level'='info', data={'lat': 1, 'lng':1}),
def tick(self):
self.cell = self.get_meta_cell()
self.tick_count += 1
# Check if session token has expired
self.check_session(self.position[0:2])
for worker in self.workers:
if worker.work() == WorkerResult.RUNNING:
return
def get_meta_cell(self):
location = self.position[0:2]
cells = self.find_close_cells(*location)
# Combine all cells into a single dict of the items we care about.
forts = []
wild_pokemons = []
catchable_pokemons = []
for cell in cells:
if "forts" in cell and len(cell["forts"]):
forts += cell["forts"]
if "wild_pokemons" in cell and len(cell["wild_pokemons"]):
wild_pokemons += cell["wild_pokemons"]
if "catchable_pokemons" in cell and len(cell["catchable_pokemons"]):
catchable_pokemons += cell["catchable_pokemons"]
return {
"forts": forts,
"wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons
}
def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
# we can call the function with no arguments and still get the position
# and map_cells
if lat is None:
lat = self.api._position_lat
if lng is None:
lng = self.api._position_lng
if alt is None:
alt = 0
if cells == []:
cellid = get_cell_ids(lat, lng)
timestamp = [0, ] * len(cellid)
response_dict = self.get_map_objects(lat, lng, timestamp, cellid)
map_objects = response_dict.get(
'responses', {}
).get('GET_MAP_OBJECTS', {})
#.........这里部分代码省略.........
示例2: PokemonGoBot
# 需要导入模块: from pokemongo_bot.socketio_server.runner import SocketIoRunner [as 别名]
# 或者: from pokemongo_bot.socketio_server.runner.SocketIoRunner import start_listening_async [as 别名]
class PokemonGoBot(object):
@property
def position(self):
return self.api._position_lat, self.api._position_lng, 0
@position.setter
def position(self, position_tuple):
self.api._position_lat, self.api._position_lng, self.api._position_alt = position_tuple
@property
def player_data(self):
"""
Returns the player data as received from the API.
:return: The player data.
:rtype: dict
"""
return self._player
def __init__(self, config):
self.config = config
self.fort_timeouts = dict()
self.pokemon_list = json.load(
open(os.path.join('data', 'pokemon.json'))
)
self.item_list = json.load(open(os.path.join('data', 'items.json')))
self.metrics = Metrics(self)
self.latest_inventory = None
self.cell = None
self.recent_forts = [None] * config.forts_max_circle_size
self.tick_count = 0
self.softban = False
self.start_position = None
self.last_map_object = None
self.last_time_map_object = 0
self.logger = logging.getLogger(type(self).__name__)
# Make our own copy of the workers for this instance
self.workers = []
def start(self):
self._setup_event_system()
self._setup_logging()
self._setup_api()
random.seed()
def _setup_event_system(self):
handlers = [LoggingHandler()]
if self.config.websocket_server_url:
if self.config.websocket_start_embedded_server:
self.sio_runner = SocketIoRunner(self.config.websocket_server_url)
self.sio_runner.start_listening_async()
websocket_handler = SocketIoHandler(
self,
self.config.websocket_server_url
)
handlers.append(websocket_handler)
if self.config.websocket_remote_control:
remote_control = WebsocketRemoteControl(self).start()
self.event_manager = EventManager(*handlers)
self._register_events()
if self.config.show_events:
self.event_manager.event_report()
sys.exit(1)
# Registering event:
# self.event_manager.register_event("location", parameters=['lat', 'lng'])
#
# Emitting event should be enough to add logging and send websocket
# message: :
# self.event_manager.emit('location', 'level'='info', data={'lat': 1, 'lng':1}),
def _register_events(self):
self.event_manager.register_event(
'location_found',
parameters=('position', 'location')
)
self.event_manager.register_event('api_error')
self.event_manager.register_event('config_error')
self.event_manager.register_event('login_started')
self.event_manager.register_event('login_failed')
self.event_manager.register_event('login_successful')
self.event_manager.register_event('set_start_location')
self.event_manager.register_event('load_cached_location')
self.event_manager.register_event('location_cache_ignored')
self.event_manager.register_event(
'position_update',
parameters=(
'current_position',
'last_position',
'distance', # optional
'distance_unit' # optional
)
)
#.........这里部分代码省略.........
示例3: PokemonGoBot
# 需要导入模块: from pokemongo_bot.socketio_server.runner import SocketIoRunner [as 别名]
# 或者: from pokemongo_bot.socketio_server.runner.SocketIoRunner import start_listening_async [as 别名]
class PokemonGoBot(Datastore):
@property
def position(self):
return self.api.actual_lat, self.api.actual_lng, self.api.actual_alt
@property
def noised_position(self):
return self.api.noised_lat, self.api.noised_lng, self.api.noised_alt
#@position.setter # these should be called through api now that gps replication is there...
#def position(self, position_tuple):
# self.api._position_lat, self.api._position_lng, self.api._position_alt = position_tuple
@property
def player_data(self):
"""
Returns the player data as received from the API.
:return: The player data.
:rtype: dict
"""
return self._player
def __init__(self, config):
# Database connection MUST be setup before migrations will work
self.database = _init_database('/data/{}.db'.format(config.username))
self.config = config
super(PokemonGoBot, self).__init__()
self.fort_timeouts = dict()
self.pokemon_list = json.load(
open(os.path.join(_base_dir, 'data', 'pokemon.json'))
)
self.item_list = json.load(open(os.path.join(_base_dir, 'data', 'items.json')))
self.metrics = Metrics(self)
self.latest_inventory = None
self.cell = None
self.recent_forts = [None] * config.forts_max_circle_size
self.tick_count = 0
self.softban = False
self.start_position = None
self.last_map_object = None
self.last_time_map_object = 0
self.logger = logging.getLogger(type(self).__name__)
self.alt = self.config.gps_default_altitude
# Make our own copy of the workers for this instance
self.workers = []
# Theading setup for file writing
self.web_update_queue = Queue.Queue(maxsize=1)
self.web_update_thread = threading.Thread(target=self.update_web_location_worker)
self.web_update_thread.start()
# Heartbeat limiting
self.heartbeat_threshold = self.config.heartbeat_threshold
self.heartbeat_counter = 0
self.last_heartbeat = time.time()
def start(self):
self._setup_event_system()
self._setup_logging()
self._setup_api()
self._load_recent_forts()
init_inventory(self)
self.display_player_info()
self._print_character_info()
if self.config.pokemon_bag_show_at_start and self.config.pokemon_bag_pokemon_info:
self._print_list_pokemon()
random.seed()
def _setup_event_system(self):
handlers = []
if self.config.logging_color:
handlers.append(ColoredLoggingHandler())
else:
handlers.append(LoggingHandler())
if self.config.enable_social:
handlers.append(SocialHandler(self))
if self.config.websocket_server_url:
if self.config.websocket_start_embedded_server:
self.sio_runner = SocketIoRunner(self.config.websocket_server_url)
self.sio_runner.start_listening_async()
websocket_handler = SocketIoHandler(
self,
self.config.websocket_server_url
)
handlers.append(websocket_handler)
if self.config.websocket_remote_control:
remote_control = WebsocketRemoteControl(self).start()
self.event_manager = EventManager(*handlers)
self._register_events()
if self.config.show_events:
self.event_manager.event_report()
#.........这里部分代码省略.........