()
| 90 | |
| 91 | |
| 92 | def main(): |
| 93 | bot = False |
| 94 | |
| 95 | def handle_sigint(*args): |
| 96 | raise SIGINTRecieved |
| 97 | signal.signal(signal.SIGINT, handle_sigint) |
| 98 | |
| 99 | def initialize_task(bot, config): |
| 100 | tree = TreeConfigBuilder(bot, config.raw_tasks).build() |
| 101 | bot.workers = tree |
| 102 | |
| 103 | def initialize(config): |
| 104 | from pokemongo_bot.datastore import Datastore |
| 105 | |
| 106 | ds = Datastore(conn_str='/data/{}.db'.format(config.username)) |
| 107 | for directory in ['pokemongo_bot', 'pokemongo_bot/cell_workers']: |
| 108 | ds.migrate(directory + '/migrations') |
| 109 | |
| 110 | bot = PokemonGoBot(ds.get_connection(), config) |
| 111 | |
| 112 | return bot |
| 113 | |
| 114 | def setup_logging(config): |
| 115 | log_level = logging.ERROR |
| 116 | |
| 117 | if config.debug: |
| 118 | log_level = logging.DEBUG |
| 119 | |
| 120 | logging.getLogger("requests").setLevel(log_level) |
| 121 | logging.getLogger("websocket").setLevel(log_level) |
| 122 | logging.getLogger("socketio").setLevel(log_level) |
| 123 | logging.getLogger("engineio").setLevel(log_level) |
| 124 | logging.getLogger("socketIO-client").setLevel(log_level) |
| 125 | logging.getLogger("pgoapi").setLevel(log_level) |
| 126 | logging.getLogger("rpc_api").setLevel(log_level) |
| 127 | |
| 128 | if config.logging: |
| 129 | logging_format = '%(message)s' |
| 130 | logging_format_options = '' |
| 131 | |
| 132 | if ('show_log_level' not in config.logging) or config.logging['show_log_level']: |
| 133 | logging_format = '[%(levelname)s] ' + logging_format |
| 134 | if ('show_process_name' not in config.logging) or config.logging['show_process_name']: |
| 135 | logging_format = '[%(name)10s] ' + logging_format |
| 136 | if ('show_thread_name' not in config.logging) or config.logging['show_thread_name']: |
| 137 | logging_format = '[%(threadName)s] ' + logging_format |
| 138 | if ('show_datetime' not in config.logging) or config.logging['show_datetime']: |
| 139 | logging_format = '[%(asctime)s] ' + logging_format |
| 140 | logging_format_options = '%Y-%m-%d %H:%M:%S' |
| 141 | |
| 142 | formatter = Formatter(logging_format,logging_format_options) |
| 143 | for handler in logging.root.handlers[:]: |
| 144 | handler.setFormatter(formatter) |
| 145 | |
| 146 | def start_bot(bot, config): |
| 147 | bot.start() |
| 148 | initialize_task(bot, config) |
| 149 | bot.metrics.capture_stats() |
no test coverage detected