class BaseStationApplication(object): LOGGING_DIRECTORY = "../data/logs" IMAGE_LOGGING_DIRECTORY = "../data/logs/images" SERVER_PORT = 8080 REMOTE_SERVER_PORT = 8081 STREAMING_SERVER_PORT = 5000 STREAMING_SERVER_IP_ADDRESS = "192.168.0.60" REMOTE_SERVER_IP_ADDRESS = "192.168.0.60" DEFAULT_STREAM_IMAGE_FILE_NAME = "../resources/default-stream-image.png" VIDEO_STREAM_BUFFER_SIZE = 1 def initialize(self): #ptvsd.enable_attach(secret = 'd3sign3') self._init_logging() self._init_services() self._embedded_application = RemotableOf(EmbeddedApplication, self._remoting_client) self._init_web_app() self._logger.close() def _init_logging(self): self._logger = Logger() self._logger.similar_log_entry_skip_interval = 0 self._csv_log_subscriber = CsvLogSubscriber(self.LOGGING_DIRECTORY) self._image_log_subscriber = ImageLogSubscriber(self.IMAGE_LOGGING_DIRECTORY) self._console_log_subscriber = ConsoleLogSubscriber() self._logger.subscribe(self._csv_log_subscriber) self._logger.subscribe(self._image_log_subscriber) self._logger.subscribe(self._console_log_subscriber) def _init_services(self): self._init_remoting_services() self._coordinate_factory = CoordinateFactory() self._world_map_service = WorldMapService(self._coordinate_factory) self._local_world_map_service = RemotableOf(LocalWorldMapService, self._remoting_client) self._pathfinding_service = PathfindingService(Pathfinder(PathSimplifier()), self._world_map_service, self._coordinate_factory) self._embedded_video_streaming_service = RemotableOf(VideoStreamingService, self._remoting_client) self._movement_executor = RemotableOf(MovementExecutor, self._remoting_client) self._path_navigator = PathNavigator(self._movement_executor, self._world_map_service, self._coordinate_factory) self._motion_service = MotionService(self._movement_executor, self._path_navigator) self._hardware_status_collector_service = RemotableOf(HardwareStatusCollectorService, self._remoting_client) self._secret_code_decoding_service = RemotableOf(SecretCodeDecodingService, self._remoting_client) self._treasure_handling_service = RemotableOf(TreasureHandlingService, self._remoting_client) self._camera_arm_control_service = RemotableOf(CameraArmControlService, self._remoting_client) self._game_cycle_control_service = GameCycleControlService(StateFactory(), self._world_map_service, self._pathfinding_service, self._motion_service, self._secret_code_decoding_service, self._treasure_handling_service, self._hardware_status_collector_service, self._local_world_map_service) self._init_video_streaming_service() def _init_video_streaming_service(self): self._original_stream_buffer = InMemoryBufferedStreamWriter(self.VIDEO_STREAM_BUFFER_SIZE) self._processed_stream_buffer = InMemoryBufferedStreamWriter(self.VIDEO_STREAM_BUFFER_SIZE) self._world_map_stream_writer = WorldMapStreamWriter(self._world_map_service, self._pathfinding_service) self._world_map_stream_writer.add_output_stream_writer(self._processed_stream_buffer) self._video_stream_dispatcher = VideoStreamDispatcher(Image.from_file(self.DEFAULT_STREAM_IMAGE_FILE_NAME)) self._video_stream_dispatcher.add_stream_writer(self._original_stream_buffer) self._video_stream_dispatcher.add_stream_writer(self._world_map_stream_writer) self._tcp_stream_reader = TcpStreamReader(self.STREAMING_SERVER_IP_ADDRESS, self.STREAMING_SERVER_PORT, self.VIDEO_STREAM_BUFFER_SIZE, False) self._video_streaming_service = VideoStreamingService(self._video_stream_dispatcher, self._original_stream_buffer, self._processed_stream_buffer, self._tcp_stream_reader) def _init_remoting_services(self): self._remote_method_invoker = RemoteMethodInvoker(JsonSerializer()) self._remoting_client = RemotingClient(self._remote_method_invoker, self.REMOTE_SERVER_IP_ADDRESS, self.REMOTE_SERVER_PORT) def _init_web_app(self): self._web_server = WebServer(self.SERVER_PORT, self._logger, self._embedded_application, self._remoting_client, self._world_map_service, self._local_world_map_service, self._pathfinding_service, self._video_streaming_service, self._embedded_video_streaming_service, self._game_cycle_control_service, self._motion_service, self._hardware_status_collector_service, self._secret_code_decoding_service, self._treasure_handling_service, self._camera_arm_control_service) self._web_server.run()
from pymongo import MongoClient from watchdog.observers.polling import PollingObserver from file_monitor import FileMonitor from web_server import WebServer from config import config from utils import init_database from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop if __name__ == "__main__": client = MongoClient() database = client.get_database(config["database_name"]) client.close() init_database(database) server = WebServer(database).web_server observer = PollingObserver() file_monitor = FileMonitor(database, config["content_path"]) observer.schedule(file_monitor, path=config["content_path"], recursive=True) print config["content_path"] observer.start() if (config["dev_mode"]): server.run(config["server_ip"], config["server_port"], debug=True) else: server = HTTPServer(WSGIContainer(server)) server.listen(config["server_port"], config["server_ip"]) IOLoop.instance().start()
def main(): bot = Bot() webbserver = WebServer(bot) webbserver.run() time.sleep(3) print("BOT started") while True: # If not running do nothing if not bot.running: continue # Check limits set by user ret = bot.check_limits() if ret: continue # If bot is not fishing cast fishing and start restart timer if not bot.is_fishing: if bot.reset is not None: bot.reset.cancel() bot.reset = threading.Timer(25, bot.fishing_failed) bot.reset.start() bot.cast_fishing() time.sleep(0.25) bot.is_fishing = True # Take screenshot and detect bobber location try: im = bot.take_screenshot() loc = bot.detect_bobber(True) except Exception as e: print("Screen Capture Error", e) # If bobber was detected if loc is not False: # Get mouse position + bobber centroid try: mloc = pg.position() loc = (loc[0] + int(bot.bobber_template.shape[1] / 2), loc[1] + int(bot.bobber_template.shape[0] / 2)) # Generate human-like movement and move mouse along the path movement = bot.human_movement(mloc, loc, 300) for x, y in movement: pg.moveTo(x, y, 0, pause=0.1e-14 + np.random.random() * 0.9e-13) # When mouse reached the bobber move the cursor under bobber bot.move_to_no_label_spot(1, True) except Exception as e: print("Mouse Movement Error", e) # Waiting for fish while bot.is_fishing: # Fish? try: if (bot.get_current_cursor() == bot.fishing_cursor_im ).all(): # Detach reset timer and variables needed for fishing bot.detach_fishing() # Move cursor to bobber's position and click time.sleep(np.random.random() * 0.8 + 0.5) pg.moveRel(None, int(bot.bobber_template.shape[0] / 2) * -0.9, duration=0.1e-1 + np.random.random() * 0.5) pg.click() # Log item bot.item_list["Successful"] += 1 time.sleep(1.8) except Exception as e: print("Fish Detection Error", e)
import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), "../")) from pymongo import MongoClient from web_server import WebServer if __name__ == "__main__": client = MongoClient() database = client.get_database("test") client.close() server = WebServer(database).web_server server.run("localhost", 4444, debug=True)
__name__ = "__main__" from pymongo import MongoClient from watchdog.observers import Observer from file_monitor import FileMonitor from web_server import WebServer from config import config from utils import init_database if __name__ == "__main__": client = MongoClient() database = client.get_database(config["database_name"]) client.close() init_database(database) server = WebServer(database).web_server observer = Observer() file_monitor = FileMonitor( database, config["content_path"] ) observer.schedule( file_monitor, path=config["content_path"], recursive=True ) observer.start() server.run( config["server_ip"], config["server_port"] )