From 2893465571fd3a28da6ed19b19657c97263a80af Mon Sep 17 00:00:00 2001 From: Adam Saudagar Date: Thu, 3 Feb 2022 05:29:10 +0530 Subject: [PATCH] pep8 cleanup --- fishy/engine/common/IEngine.py | 5 +---- fishy/engine/common/qr_detection.py | 6 ------ fishy/engine/common/window.py | 2 +- fishy/engine/common/window_server.py | 4 +--- fishy/engine/fullautofisher/controls.py | 2 ++ fishy/engine/fullautofisher/engine.py | 7 +------ fishy/engine/semifisher/engine.py | 1 - fishy/gui/config_top.py | 5 ----- fishy/gui/discord_login.py | 1 + fishy/gui/gui.py | 2 -- fishy/gui/main_gui.py | 4 ++-- fishy/helper/auto_update.py | 18 +++++++++--------- fishy/helper/helper.py | 11 +++++------ fishy/helper/migration.py | 3 +-- fishy/web/web.py | 8 ++------ 15 files changed, 26 insertions(+), 53 deletions(-) diff --git a/fishy/engine/common/IEngine.py b/fishy/engine/common/IEngine.py index f51d220..2d5338a 100644 --- a/fishy/engine/common/IEngine.py +++ b/fishy/engine/common/IEngine.py @@ -1,15 +1,12 @@ import logging -import traceback import typing from threading import Thread from typing import Callable import cv2 -from playsound import playsound from fishy.engine.common.window import WindowClient from fishy.gui.funcs import GUIFuncsMock -from fishy.helper import helper from fishy.helper.helper import print_exc if typing.TYPE_CHECKING: @@ -23,7 +20,7 @@ class IEngine: # 0 - off, 1 - running, 2 - quitting self.state = 0 self.window = None - self.thread: Thread = None + self.thread = None @property def gui(self): diff --git a/fishy/engine/common/qr_detection.py b/fishy/engine/common/qr_detection.py index 5284329..5a77db2 100644 --- a/fishy/engine/common/qr_detection.py +++ b/fishy/engine/common/qr_detection.py @@ -1,13 +1,7 @@ -import logging -import os -from datetime import datetime - import cv2 import numpy as np from pyzbar.pyzbar import decode, ZBarSymbol -from fishy.helper.helper import get_documents - def image_pre_process(img): scale_percent = 100 # percent of original size diff --git a/fishy/engine/common/window.py b/fishy/engine/common/window.py index e451e1c..a27614d 100644 --- a/fishy/engine/common/window.py +++ b/fishy/engine/common/window.py @@ -89,7 +89,7 @@ class WindowClient: def show(self, to_show, resize=None, func=None): """ Displays the processed image for debugging purposes - :param ready_img: send ready image, just show the `ready_img` directly + :param to_show: false to destroy the window :param resize: scale the image to make small images more visible :param func: function to process the image """ diff --git a/fishy/engine/common/window_server.py b/fishy/engine/common/window_server.py index cb9e136..d4535f4 100644 --- a/fishy/engine/common/window_server.py +++ b/fishy/engine/common/window_server.py @@ -1,17 +1,14 @@ import logging import math -import traceback from enum import Enum from threading import Thread -import cv2 import d3dshot import pywintypes import win32api import win32gui from ctypes import windll -from fishy.helper.config import config from fishy.helper.helper import print_exc @@ -38,6 +35,7 @@ def init(): Executed once before the main loop, Finds the game window, and calculates the offset to remove the title bar """ + # noinspection PyUnresolvedReferences try: WindowServer.hwnd = win32gui.FindWindow(None, "Elder Scrolls Online") diff --git a/fishy/engine/fullautofisher/controls.py b/fishy/engine/fullautofisher/controls.py index e18db67..faf66a9 100644 --- a/fishy/engine/fullautofisher/controls.py +++ b/fishy/engine/fullautofisher/controls.py @@ -4,6 +4,8 @@ from pynput.keyboard import Key from fishy.helper import hotkey +# todo: unused code remove it + def get_controls(controls: 'Controls'): controls = [ diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index ec2dd6f..ac9789b 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -1,10 +1,8 @@ import logging import math import time -import traceback from threading import Thread -import cv2 from pynput import keyboard, mouse from fishy.engine import SemiFisherEngine @@ -16,9 +14,8 @@ from fishy.engine.fullautofisher.mode.player import Player from fishy.engine.fullautofisher.mode.recorder import Recorder from fishy.engine.common.qr_detection import (get_qr_location, get_values_from_image, image_pre_process) -from fishy.engine.semifisher import fishing_event, fishing_mode +from fishy.engine.semifisher import fishing_mode from fishy.engine.semifisher.fishing_mode import FishingMode -from fishy.helper import hotkey from fishy.helper.config import config from fishy.helper.helper import wait_until, is_eso_active, sign, print_exc @@ -201,8 +198,6 @@ class FullAuto(IEngine): if __name__ == '__main__': - logging.getLogger("").setLevel(logging.DEBUG) - hotkey.initalize() # noinspection PyTypeChecker bot = FullAuto(None) bot.toggle_start() diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 6e2892d..e514e35 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -1,6 +1,5 @@ import logging import time -import traceback import typing from threading import Thread from typing import Callable, Optional diff --git a/fishy/gui/config_top.py b/fishy/gui/config_top.py index 1fed5d0..e682231 100644 --- a/fishy/gui/config_top.py +++ b/fishy/gui/config_top.py @@ -2,21 +2,16 @@ import logging import os import tkinter as tk import tkinter.ttk as ttk -import typing from tkinter.filedialog import askopenfilename from fishy.engine.common.event_handler import IEngineHandler from fishy.engine.fullautofisher.mode.imode import FullAutoMode -from fishy.helper import helper from fishy import web from fishy.helper import helper from fishy.helper.config import config from fishy.helper.popup import PopUp -if typing.TYPE_CHECKING: - from fishy.gui import GUI - def start_fullfisher_config(gui: 'GUI'): top = PopUp(helper.empty_function, gui._root, background=gui._root["background"]) diff --git a/fishy/gui/discord_login.py b/fishy/gui/discord_login.py index d353266..91b082c 100644 --- a/fishy/gui/discord_login.py +++ b/fishy/gui/discord_login.py @@ -26,6 +26,7 @@ def discord_login(gui: 'GUI'): top.destroy() top_running[0] = False + # noinspection PyUnresolvedReferences def check(): code = int(login_code.get()) if login_code.get().isdigit() else 0 if web.login(config.get("uid"), code): diff --git a/fishy/gui/gui.py b/fishy/gui/gui.py index ac10453..a01272d 100644 --- a/fishy/gui/gui.py +++ b/fishy/gui/gui.py @@ -1,4 +1,3 @@ -import logging import queue import threading import tkinter as tk @@ -15,7 +14,6 @@ from fishy.gui.funcs import GUIFuncs from ..helper.config import config from ..helper.helper import wait_until from . import main_gui -from .log_config import GuiLogger @dataclass diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index cce29c4..2912005 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -10,7 +10,7 @@ from ttkthemes import ThemedTk from fishy import helper from fishy.web import web -from ..constants import chalutier, lam2, fishyqr +from ..constants import fishyqr from ..helper.config import config from .discord_login import discord_login from ..helper.hotkey.hotkey_process import hotkey @@ -131,7 +131,7 @@ def _create(gui: 'GUI'): hotkey.hook(Key.F9, gui.funcs.start_engine) - # noinspection PyProtectedMember + # noinspection PyProtectedMember,PyUnresolvedReferences def set_destroy(): if gui._bot_running: if not tk.messagebox.askyesno(title="Quit?", message="Bot engine running. Quit Anyway?"): diff --git a/fishy/helper/auto_update.py b/fishy/helper/auto_update.py index 8bbd7d4..ed7bb8e 100644 --- a/fishy/helper/auto_update.py +++ b/fishy/helper/auto_update.py @@ -38,29 +38,29 @@ def _normalize_version(v): return rv -def _get_highest_version(index, pkg): +def _get_highest_version(_index, _pkg): """ Crawls web for latest version name then returns latest version - :param index: website to check - :param pkg: package name + :param _index: website to check + :param _pkg: package name :return: latest version normalized """ - url = "{}/{}/".format(index, pkg) + url = "{}/{}/".format(_index, _pkg) html = urllib.request.urlopen(url) if html.getcode() != 200: raise Exception # not found soup = BeautifulSoup(html.read(), "html.parser") - versions = [] + _versions = [] for link in soup.find_all('a'): text = link.get_text() try: - version = re.search(pkg + r'-(.*)\.tar\.gz', text).group(1) - versions.append(_normalize_version(version)) + version = re.search(_pkg + r'-(.*)\.tar\.gz', text).group(1) + _versions.append(_normalize_version(version)) except AttributeError: pass - if len(versions) == 0: + if len(_versions) == 0: raise Exception # no version - return max(versions) + return max(_versions) def _get_current_version(): diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index a1eac7a..d14d505 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -15,14 +15,12 @@ from zipfile import ZipFile import requests import winshell -from fishy.gui import update_dialog from playsound import playsound from win32com.client import Dispatch from win32comext.shell import shell, shellcon from win32gui import GetForegroundWindow, GetWindowText import fishy -from fishy import web from fishy.constants import libgps, lam2, fishyqr from fishy.helper.config import config @@ -129,8 +127,8 @@ def create_shortcut(anti_ghosting: bool): desktop = winshell.desktop() path = os.path.join(desktop, "Fishybot ESO.lnk") - shell = Dispatch('WScript.Shell') - shortcut = shell.CreateShortCut(path) + _shell = Dispatch('WScript.Shell') + shortcut = _shell.CreateShortCut(path) if anti_ghosting: shortcut.TargetPath = r"C:\Windows\System32\cmd.exe" @@ -170,6 +168,7 @@ def addon_exists(name, url=None, v=None): def get_addonversion(name, url=None, v=None): if addon_exists(name): txt = name + ".txt" + # noinspection PyBroadException try: with open(os.path.join(get_addondir(), name, txt)) as f: for line in f: @@ -241,9 +240,9 @@ def _get_id(thread): # returns id of the respective thread if hasattr(thread, '_thread_id'): return thread._thread_id - for id, thread in threading._active.items(): + for _id, thread in threading._active.items(): if thread is thread: - return id + return _id def kill_thread(thread): diff --git a/fishy/helper/migration.py b/fishy/helper/migration.py index d6e992c..e45e7a9 100644 --- a/fishy/helper/migration.py +++ b/fishy/helper/migration.py @@ -2,8 +2,7 @@ import logging from fishy.helper.auto_update import _normalize_version -from fishy.constants import chalutier, version -from fishy.helper import helper +from fishy.constants import version from .config import config diff --git a/fishy/web/web.py b/fishy/web/web.py index 8b4ec7d..2c69ea7 100644 --- a/fishy/web/web.py +++ b/fishy/web/web.py @@ -4,8 +4,6 @@ import requests from whatsmyip.ip import get_ip from whatsmyip.providers import GoogleDnsProvider -from fishy import helper - from ..constants import apiversion from ..helper.config import config from . import urls @@ -88,8 +86,6 @@ def sub(): @fallback((False, False)) def is_subbed(): """ - :param uid: - :param lazy: :return: Tuple[is_subbed, success] """ @@ -102,8 +98,8 @@ def is_subbed(): if response.status_code != 200: return False, False - is_subbed = response.json()["subbed"] - return is_subbed, True + _is_subbed = response.json()["subbed"] + return _is_subbed, True @fallback(None)