diff --git a/fishy/__main__.py b/fishy/__main__.py index 553a020..e8276ef 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -14,10 +14,15 @@ Options: """ import cv2 +from docopt import docopt +from pynput.keyboard import Listener from fishy.systems import * import logging +from fishy.systems.config import Config +from fishy.systems.gui import GUI, GUIStreamHandler + """ Start reading from `init.py` """ @@ -37,15 +42,15 @@ def on_release(key): if c[0] == Control.Keywords.StartPause: if not G.pause: - print("PAUSED") + logging.info("PAUSED") G.pause = True return if PixelLoc.config(): - print("STARTED") + logging.info("STARTED") G.pause = False else: - print("addon properly not installed, if it is installed try restarting the game.") + logging.info("addon properly not installed, if it is installed try restarting the game.") elif c[0] == Control.Keywords.Debug: G.debug = not G.debug @@ -108,6 +113,14 @@ def startFishing(): def main(): + rootLogger = logging.getLogger('') + rootLogger.setLevel(logging.DEBUG) + + gui = GUI(Config()) + gui.start() + new_console = GUIStreamHandler(gui) + rootLogger.addHandler(new_console) + logging.info("yo") G.arguments = docopt(__doc__) if G.arguments["--version"]: quit() diff --git a/fishy/systems/fishing_event.py b/fishy/systems/fishing_event.py index 1b01502..48cb812 100644 --- a/fishy/systems/fishing_event.py +++ b/fishy/systems/fishing_event.py @@ -2,6 +2,7 @@ Defines different fishing modes (states) which acts as state for state machine also implements callbacks which is called when states are changed """ +import logging import time from abc import abstractmethod, ABC @@ -34,7 +35,7 @@ class HookEvent(FishEvent): G.fishCaught += 1 G.totalFishCaught += 1 timeToHook = time.time() - G.stickInitTime - print("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(G.fishCaught) + " caught " + "in " + str( + logging.info("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(G.fishCaught) + " caught " + "in " + str( round_float(timeToHook)) + " secs. " + "Total: " + str(G.totalFishCaught)) pyautogui.press('e') @@ -85,9 +86,9 @@ class IdleEvent(FishEvent): net.sendHoleDeplete(G.fishCaught) if previousMode.name == "hook": - print("HOLE DEPLETED") + logging.info("HOLE DEPLETED") elif previousMode.name == "stick": - print("FISHING INTERRUPTED") + logging.info("FISHING INTERRUPTED") def onExitCallback(self, currentMode): pass diff --git a/fishy/systems/fishy_network.py b/fishy/systems/fishy_network.py index e703eff..2ebc28f 100644 --- a/fishy/systems/fishy_network.py +++ b/fishy/systems/fishy_network.py @@ -1,3 +1,4 @@ +import logging import socket import json @@ -20,9 +21,9 @@ def send_message(message, count=1): sock.send(bytes(message, "utf-8")) sock.close() except ConnectionRefusedError: - print("Connection Refused, please turn on service on mobile") + logging.info("Connection Refused, please turn on service on mobile") except TimeoutError: - print("Timeout Error") + logging.info("Timeout Error") if count < RETRY_LIMIT: send_message(message, count+1) diff --git a/fishy/systems/gui.py b/fishy/systems/gui.py index fe8b3d0..d4d4379 100644 --- a/fishy/systems/gui.py +++ b/fishy/systems/gui.py @@ -1,5 +1,7 @@ +import logging import time from enum import Enum +from logging import StreamHandler from tkinter import * from tkinter.ttk import * from ttkthemes import ThemedTk @@ -9,6 +11,16 @@ import threading from fishy.systems.config import Config +class GUIStreamHandler(StreamHandler): + def __init__(self, gui): + StreamHandler.__init__(self) + self.gui = gui + + def emit(self, record): + msg = self.format(record) + self.gui.writeToLog(msg) + + class Callback(Enum): START = 0, SHORTCUT = 1, @@ -46,8 +58,7 @@ class GUICallback: class GUI: - def __init__(self, gui_callback=None, - config: Config = None): + def __init__(self,config: Config, gui_callback=None): self.callbacks = GUICallback() if gui_callback is None else gui_callback self.config = config self.start_restart = False @@ -170,7 +181,7 @@ class GUI: def start(ip, actionkey, fullscreen): - print(f"{ip}, {actionkey}, {fullscreen}") + logging.info(f"{ip}, {actionkey}, {fullscreen}") def main(): diff --git a/fishy/systems/window.py b/fishy/systems/window.py index 3ba4f1e..6157d1d 100644 --- a/fishy/systems/window.py +++ b/fishy/systems/window.py @@ -1,3 +1,5 @@ +import logging + import cv2 import math import win32gui @@ -48,7 +50,7 @@ class Window: Window.titleOffset = 0 except pywintypes.error: - print("Game window not found") + logging.info("Game window not found") quit() @staticmethod @@ -72,7 +74,7 @@ class Window: Window.Screen = tempScreen[crop[1]:crop[3], crop[0]:crop[2]] if Window.Screen.size == 0: - print("Don't minimize or drag game window outside the screen") + logging.info("Don't minimize or drag game window outside the screen") quit(1) @staticmethod