Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added param --rootPath to store session,logs in a predefined directory. #169

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ def __getLoginTokens(self, form: str) -> tuple[str, str]:
return token, state

def __dumpCookies(self):
with open(f'./sessions/{self.account}.saved', 'wb') as f:
with open(f'{self.config.rootPath}/sessions/{self.account}.saved', 'wb') as f:
pickle.dump(self.client.cookies, f)

def __loadCookies(self):
if Path(f'./sessions/{self.account}.saved').exists():
with open(f'./sessions/{self.account}.saved', 'rb') as f:
if Path(f'{self.config.rootPath}/sessions/{self.account}.saved').exists():
with open(f'{self.config.rootPath}/sessions/{self.account}.saved', 'rb') as f:
self.client.cookies.update(pickle.load(f))
return True
return False
9 changes: 5 additions & 4 deletions src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from pathlib import Path

from Exceptions.InvalidCredentialsException import InvalidCredentialsException


class Config:
"""
A class that loads and stores the configuration
Expand All @@ -14,14 +12,15 @@ class Config:
REMOTE_BEST_STREAMS_URL = "https://raw.githubusercontent.com/LeagueOfPoro/CapsuleFarmerEvolved/master/config/bestStreams.txt"
RIOT_API_KEY = "0TvQnueqKa5mxJntVWt0w4LpLfEkrV1Ta8rQBb9Z"

def __init__(self, configPath: str) -> None:
def __init__(self, configPath: str, rootPath: str) -> None:
"""
Loads the configuration file into the Config object

:param configPath: string, path to the configuration file
"""

self.accounts = {}
self.rootPath = rootPath
try:
configPath = self.__findConfig(configPath)
with open(configPath, "r", encoding='utf-8') as f:
Expand All @@ -45,7 +44,7 @@ def __init__(self, configPath: str) -> None:
self.connectorDrops = config.get("connectorDropsUrl", "")
self.showHistoricalDrops = config.get("showHistoricalDrops", True)
except FileNotFoundError as ex:
print(f"[red]CRITICAL ERROR: The configuration file cannot be found at {configPath}\nHave you extacted the ZIP archive and edited the configuration file?")
print(f"[red]CRITICAL ERROR: The configuration file cannot be found at {configPath} nor at {rootPath}.\nHave you extacted the ZIP archive and edited the configuration file?")
print("Press any key to exit...")
input()
raise ex
Expand Down Expand Up @@ -88,6 +87,8 @@ def __findConfig(self, configPath):
configPath = Path(configPath)
if configPath.exists():
return configPath
if (Path(self.rootPath) / Path("config/config.yaml")).exists():
return Path(self.rootPath) / Path("config/config.yaml")
if Path("../config/config.yaml").exists():
return Path("../config/config.yaml")
if Path("config/config.yaml").exists():
Expand Down
4 changes: 2 additions & 2 deletions src/Logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

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

fileHandler = RotatingFileHandler(
"./logs/capsulefarmer.log",
f"{rootPath}/logs/capsulefarmer.log",
mode="a+",
maxBytes=FILE_SIZE,
backupCount=BACKUP_COUNT,
Expand Down
10 changes: 6 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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')
parser.add_argument("--rootPath", dest="rootPath", default=".",
help="Path to the dir where all files will be manipulated")
args = parser.parse_args()

print("*********************************************************")
Expand All @@ -34,10 +36,10 @@ def init() -> tuple[logging.Logger, Config]:
print("*********************************************************")
print()

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, CURRENT_VERSION)
(Path(args.rootPath) / Path("logs/")).mkdir(parents=True, exist_ok=True)
(Path(args.rootPath) / Path("sessions/")).mkdir(parents=True, exist_ok=True)
config = Config(args.configPath, args.rootPath)
log = Logger.createLogger(config.debug, CURRENT_VERSION, args.rootPath)
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")
Expand Down