More converting

This commit is contained in:
Nikolaj Danger
2021-03-30 18:27:47 +02:00
parent e8c7fb95e5
commit a8a7e5eabd
7 changed files with 113 additions and 74 deletions

View File

@ -1,5 +1,5 @@
"""A collections of utilities used by Gwendolyn and her functions"""
__all__ = ["Options"]
__all__ = ["Options", "Credentials"]
from .options import Options
from .helperClasses import Options, Credentials

46
utils/helperClasses.py Normal file
View File

@ -0,0 +1,46 @@
def sanitize(data : str, options : bool = False):
data = data.splitlines()
dct = {}
for line in data:
if line[0] != "#" and ":" in line:
lineValues = line.split(":")
lineValues[0] = lineValues[0].lower()
lineValues[1] = lineValues[1].replace(" ", "")
if options:
lineValues[1] = lineValues[1].lower()
if lineValues[0] in ["testing guild ids", "admins"]:
lineValues[1] = lineValues[1].split(",")
if all(i.isnumeric() for i in lineValues[1]):
lineValues[1] = [int(i) for i in lineValues[1]]
if any(i == lineValues[1] for i in ["true", "false"]):
lineValues[1] = (lineValues[1] == "true")
dct[lineValues[0]] = lineValues[1]
return dct
class Options():
def __init__(self):
with open("options.txt","r") as f:
data = sanitize(f.read(), True)
self.testing = data["testing"]
self.guildIds = data["testing guild ids"]
self.admins = data["admins"]
class Credentials():
def __init__(self):
with open("credentials.txt","r") as f:
data = sanitize(f.read())
self.token = data["bot token"]
self.finnhubKey = data["finnhub api key"]
self.wordnikKey = data["wordnik api key"]
self.mongoDBUser = data["mongodb user"]
self.mongoDBPassword = data["mongodb password"]
self.wolfKey = data["wolframalpha appid"]
self.radarrKey = data["radarr api key"]
self.sonarrKey = data["sonarr api key"]

View File

@ -1,9 +0,0 @@
class Options():
def __init__(self):
with open("options.txt","r") as f:
data = f.read().splitlines()
self.testing = (data[0][8:].replace(" ","").lower() == "true")
guildIds = data[1][17:].replace(" ","").split(",")
self.guildIds = [int(i) for i in guildIds]
self.admins = data[2][7:].replace(" ","").split(",")