Skip to content

Commit

Permalink
fix: Removed instancing of log helper. (#88)
Browse files Browse the repository at this point in the history
* Removed instancing of log helper.

* Moved imports together.
  • Loading branch information
hypixus committed Feb 8, 2023
1 parent 4e551a2 commit 68dfbf2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
12 changes: 8 additions & 4 deletions src/Logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@


class Logger:
def createLogger(self, debug: bool):
if (debug):
@staticmethod
def createLogger(debug: bool):
if debug:
level = logging.DEBUG
else:
level = logging.WARNING

logging.basicConfig(filename=f'./logs/capsulefarmer-{datetime.now().strftime("%Y-%m-%d")}.log', filemode="a+", format='%(asctime)s %(levelname)s: %(message)s', level=level)

logging.basicConfig(filename=f'./logs/capsulefarmer-{datetime.now().strftime("%Y-%m-%d")}.log',
filemode="a+",
format='%(asctime)s %(levelname)s: %(message)s',
level=level)
log = logging.getLogger("League of Poro")
log.info("-------------------------------------------------")
log.info("---------------- Program started ----------------")
Expand Down
17 changes: 10 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from FarmThread import FarmThread
from GuiThread import GuiThread
from threading import Lock
from Logger import Logger
from Config import Config
from Logger import Logger
import logging
import sys
import argparse
from rich import print
Expand All @@ -14,10 +15,10 @@
from Stats import Stats
from VersionManager import VersionManager


CURRENT_VERSION = 1.2

def init() -> tuple[Logger, Config]:

def init() -> tuple[logging.Logger, Config]:
parser = argparse.ArgumentParser(description='Farm Esports Capsules by watching all matches on lolesports.com.')
parser.add_argument('-c', '--config', dest="configPath", default="./config.yaml",
help='Path to a custom config file')
Expand All @@ -34,14 +35,15 @@ def init() -> tuple[Logger, Config]:
Path("./logs/").mkdir(parents=True, exist_ok=True)
Path("./sessions/").mkdir(parents=True, exist_ok=True)
config = Config(args.configPath)
log = Logger().createLogger(config.debug)
log = Logger.createLogger(config.debug)
if not VersionManager.isLatestVersion(CURRENT_VERSION):
log.warning("!!! NEW VERSION AVAILABLE !!! Download it from: https://github.com/LeagueOfPoro/CapsuleFarmerEvolved/releases/latest")
print("[bold red]!!! NEW VERSION AVAILABLE !!!\nDownload it from: https://github.com/LeagueOfPoro/CapsuleFarmerEvolved/releases/latest\n")

return log, config

def main(log: Logger, config: Config):

def main(log: logging.Logger, config: Config):
farmThreads = {}
refreshLock = Lock()
locks = {"refreshLock": refreshLock}
Expand Down Expand Up @@ -87,12 +89,13 @@ def main(log: Logger, config: Config):
for account in toDelete:
del farmThreads[account]


if __name__ == '__main__':
try:
log, config = init()
main(log, config)
except (KeyboardInterrupt, SystemExit):
print('Exitting. Thank you for farming with us!')
print('Exiting. Thank you for farming with us!')
sys.exit()
except CapsuleFarmerEvolvedException as e:
log.error(f'An error has occured: {e}')
log.error(f'An error has occurred: {e}')

0 comments on commit 68dfbf2

Please sign in to comment.