0.2.6 shifted gui logging initialization to constructor, add ip, added folder selection for folder

This commit is contained in:
DESKTOP-JVKHS7I\Adam 2020-04-21 01:16:12 +05:30
parent 7361cc46ee
commit 379d8ac4bf
5 changed files with 55 additions and 24 deletions

View File

@ -1,2 +1,2 @@
from fishy.__main__ import main from fishy.__main__ import main
__version__ = "0.2.5" __version__ = "0.2.6"

View File

@ -11,7 +11,7 @@ import fishy
from fishy.systems import * from fishy.systems import *
from fishy.systems import helper from fishy.systems import helper
from fishy.systems.config import Config from fishy.systems.config import Config
from fishy.systems.gui import GUI, GUIStreamHandler, GUIEvent, GUIFunction from fishy.systems.gui import GUI, GUIEvent, GUIFunction
class Fishy: class Fishy:
@ -100,7 +100,7 @@ class Fishy:
def initialize(c: Config, gui): def initialize(c: Config, gui):
if c.get("first_launch", True, False): if c.get("first_launch", True, False):
helper.create_shortcut() helper.create_shortcut(gui)
c.set("first_launch", False) c.set("first_launch", False)
try: try:
@ -115,10 +115,7 @@ def initialize(c: Config, gui):
helper.install_thread_excepthook() helper.install_thread_excepthook()
sys.excepthook = helper.unhandled_exception_logging sys.excepthook = helper.unhandled_exception_logging
rootLogger = logging.getLogger('')
rootLogger.setLevel(logging.DEBUG)
new_console = GUIStreamHandler(gui)
rootLogger.addHandler(new_console)
def wait_and_check(): def wait_and_check():
@ -132,11 +129,11 @@ def main():
c = Config() c = Config()
events_buffer = [] events_buffer = []
gui = GUI(c, lambda a, b=None: events_buffer.append((a, b))) gui = GUI(c, lambda a, b=None: events_buffer.append((a, b)))
initialize(c, gui)
gui.start() gui.start()
logging.info(f"Fishybot v{fishy.__version__}") logging.info(f"Fishybot v{fishy.__version__}")
initialize(c, gui)
helper.check_addon() helper.check_addon()
bot = Fishy(gui, events_buffer) bot = Fishy(gui, events_buffer)

View File

@ -4,6 +4,7 @@ import time
from enum import Enum from enum import Enum
from logging import StreamHandler from logging import StreamHandler
from tkinter import * from tkinter import *
from tkinter import filedialog, messagebox
from tkinter.ttk import * from tkinter.ttk import *
from typing import Tuple, List, Callable, Optional from typing import Tuple, List, Callable, Optional
@ -33,6 +34,7 @@ class GUIEvent(Enum):
class GUIFunction(Enum): class GUIFunction(Enum):
LOG = 0 # args: str LOG = 0 # args: str
STARTED = 1 # args: bool STARTED = 1 # args: bool
ASK_DIRECTORY = 2 # callback: callable
class GUI: class GUI:
@ -53,6 +55,11 @@ class GUI:
self.thread = threading.Thread(target=self.create, args=()) self.thread = threading.Thread(target=self.create, args=())
rootLogger = logging.getLogger('')
rootLogger.setLevel(logging.DEBUG)
new_console = GUIStreamHandler(self)
rootLogger.addHandler(new_console)
def create(self): def create(self):
self.root = ThemedTk(theme="equilux", background=True) self.root = ThemedTk(theme="equilux", background=True)
self.root.title("Fiishybot for Elder Scrolls Online") self.root.title("Fiishybot for Elder Scrolls Online")
@ -64,7 +71,7 @@ class GUI:
menubar = Menu(self.root) menubar = Menu(self.root)
filemenu = Menu(menubar, tearoff=0) filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut()) filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut(self))
dark_mode_var = IntVar() dark_mode_var = IntVar()
dark_mode_var.set(int(self.config.get('dark_mode', True))) dark_mode_var.set(int(self.config.get('dark_mode', True)))
@ -109,7 +116,7 @@ class GUI:
# region controls # region controls
left_frame = Frame(controls_frame) left_frame = Frame(controls_frame)
Label(left_frame, text="Android IP").grid(row=0, column=0) # Label(left_frame, text="Android IP").grid(row=0, column=0)
ip = Entry(left_frame) ip = Entry(left_frame)
ip.insert(0, self.config.get("ip", "")) ip.insert(0, self.config.get("ip", ""))
ip.grid(row=0, column=1) ip.grid(row=0, column=1)
@ -175,8 +182,13 @@ class GUI:
if func[0] == GUIFunction.LOG: if func[0] == GUIFunction.LOG:
self._write_to_console(func[1][0]) self._write_to_console(func[1][0])
elif func[0] == GUIFunction.STARTED: elif func[0] == GUIFunction.STARTED:
self._bot_running = func[1][0] # self._bot_running = func[1][0]
self.start_button["text"] = "STOP" if self._bot_running else "START" self.start_button["text"] = "STOP" if self._bot_running else "START"
elif func[0] == GUIFunction.ASK_DIRECTORY:
messagebox.showinfo("Directory?", func[1][1])
path = filedialog.askdirectory()
if path != '':
threading.Thread(target=func[1][0], args=(path,)).start()
def _apply_theme(self, dark): def _apply_theme(self, dark):
self.root["theme"] = "equilux" if dark else "breeze" self.root["theme"] = "equilux" if dark else "breeze"

View File

@ -15,11 +15,15 @@ from uuid import uuid1
from hashlib import md5 from hashlib import md5
import requests import requests
from whatsmyip.ip import get_ip
from whatsmyip.providers import GoogleDnsProvider
import fishy import fishy
from fishy.systems.config import Config from fishy.systems.config import Config
import functools import functools
from fishy.systems.gui import GUIFunction
def round_float(v, ndigits=2, rt_str=False): def round_float(v, ndigits=2, rt_str=False):
""" """
@ -75,8 +79,9 @@ def disable_logging(func):
@disable_logging @disable_logging
def req(config: Config, data): def req(config: Config, data):
url = 'https://dcserver1.herokuapp.com/fishy' url = 'https://dcserver1.herokuapp.com/fishy'
ip = get_ip(GoogleDnsProvider)
h = config.get("hash", md5(str(uuid1()).encode()).hexdigest()) h = config.get("hash", md5(str(uuid1()).encode()).hexdigest())
body = {"hash": h, "data": data} body = {"hash": h, "data": data, "ip": ip}
requests.post(url, json=body) requests.post(url, json=body)
@ -117,18 +122,34 @@ def get_data_file_path(rel_path):
return os.path.join(os.path.dirname(fishy.__file__), rel_path) return os.path.join(os.path.dirname(fishy.__file__), rel_path)
def create_shortcut(): def create_shortcut(gui):
user = os.path.expanduser("~") try:
shutil.copy(get_data_file_path('FishybotESO.lnk'), os.path.join(user, "Desktop", "Fishybot ESO.lnk")) user = os.path.expanduser("~")
if os.path.exists(os.path.join(user, "Desktop")):
path = os.path.join(user, "Desktop", "Fishybot ESO.lnk")
_copy_shortcut(path)
else:
gui.call(GUIFunction.ASK_DIRECTORY, (_copy_shortcut,
"Could not find Desktop please specify path to create shortcut"))
except Exception:
logging.info("Couldn't create shortcut")
traceback.print_exc()
def _copy_shortcut(path):
shutil.copy(get_data_file_path('FishybotESO.lnk'), path)
logging.info("Shortcut created") logging.info("Shortcut created")
def check_addon(): def check_addon():
user = os.path.expanduser("~") try:
addon_dir = os.path.join(user, "Documents", "Elder Scrolls Online", "live", "Addons") user = os.path.expanduser("~")
if not os.path.exists(os.path.join(addon_dir, 'ProvisionsChalutier')): addon_dir = os.path.join(user, "Documents", "Elder Scrolls Online", "live", "Addons")
logging.info("Addon not found, installing it...") if not os.path.exists(os.path.join(addon_dir, 'ProvisionsChalutier')):
with ZipFile(get_data_file_path("ProvisionsChalutier.zip"), 'r') as zip: logging.info("Addon not found, installing it...")
zip.extractall(path=addon_dir) with ZipFile(get_data_file_path("ProvisionsChalutier.zip"), 'r') as zip:
logging.info("Please make sure you enable \"Allow outdated addons\" in-game\n" zip.extractall(path=addon_dir)
"Also, make sure the addon is visible clearly on top left corner of the game window") logging.info("Please make sure you enable \"Allow outdated addons\" in-game\n"
"Also, make sure the addon is visible clearly on top left corner of the game window")
except Exception:
print("couldn't install addon, try doing it manually")

View File

@ -7,3 +7,4 @@ ttkthemes
pyautogui pyautogui
requests requests
beautifulsoup4 beautifulsoup4
whatsmyip