forked from LeagueOfPoro/CapsuleFarmerEvolved
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.py
64 lines (54 loc) · 2.55 KB
/
Config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import yaml
from yaml.parser import ParserError
from rich import print
from Exceptions.InvalidCredentialsException import InvalidCredentialsException
class Config:
"""
A class that loads and stores the configuration
"""
def __init__(self, configPath: str) -> None:
"""
Loads the configuration file into the Config object
:param configPath: string, path to the configuration file
"""
self.accounts = {}
try:
with open(configPath, "r", encoding='utf-8') as f:
config = yaml.safe_load(f)
accs = config.get("accounts")
onlyDefaultUsername = True
for account in accs:
self.accounts[account] = {
"username": accs[account]["username"],
"password": accs[account]["password"],
}
if "username" != accs[account]["username"]:
onlyDefaultUsername = False
if onlyDefaultUsername:
raise InvalidCredentialsException
self.debug = config.get("debug", False)
self.connectorDrops = config.get("connectorDropsUrl", "")
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("Press any key to exit...")
input()
raise ex
except (ParserError, KeyError) as ex:
print(f"[red]CRITICAL ERROR: The configuration file does not have a valid format.\nPlease, check it for extra spaces and other characters.\nAlternatively, use confighelper.html to generate a new one.")
print("Press any key to exit...")
input()
raise ex
except InvalidCredentialsException as ex:
print(f"[red]CRITICAL ERROR: There are only default credentials in the configuration file.\nYou need to add you Riot account login to config.yaml to receive drops.")
print("Press any key to exit...")
input()
raise ex
with open("bestStreams.txt", "r", encoding='utf-8') as f:
self.bestStreams = f.read().splitlines()
def getAccount(self, account: str) -> dict:
"""
Get account information
:param account: string, name of the account
:return: dictionary, account information
"""
return self.accounts[account]