From 9a880d343cb0da9ed44b0944018d9d294d3caebd Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sun, 17 Jul 2016 06:49:05 -0500 Subject: [PATCH] Added new method for saving content as a json file instead of mysql --- cogs/core.py | 9 +++++---- cogs/utils/config.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cogs/core.py b/cogs/core.py index a4ec098..33fe577 100644 --- a/cogs/core.py +++ b/cogs/core.py @@ -83,10 +83,11 @@ class Core: url += query # This will check if the channel is a 'nsfw' channel, if so add 'explicit' to the search term - cursor = config.getCursor() - cursor.execute('use {}'.format(config.db_default)) - cursor.execute('select * from nsfw_channels') - result = cursor.fetchall() + #cursor = config.getCursor() + #cursor.execute('use {}'.format(config.db_default)) + #cursor.execute('select * from nsfw_channels') + #result = cursor.fetchall() + nsfw_channels = config.getContent("nsfw_channels") if {'channel_id': '{}'.format(ctx.message.channel.id)} in result: url += ",+explicit&filter_id=95938" config.closeConnection() diff --git a/cogs/utils/config.py b/cogs/utils/config.py index a784050..957b722 100644 --- a/cogs/utils/config.py +++ b/cogs/utils/config.py @@ -42,7 +42,15 @@ def closeConnection(): connection.close() def saveContent(key: str, content): - with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as f: - jfile = json.load(f) - if key in content: - jfile[key]= content + with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf: + data = json.load(jf) + data[key] = content + jf.seek(0) + json.dump(data, jf, indent=4) + jf.close() + +def getContent(key: str): + with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf: + data = json.load(jf) + jf.close() + return data[key]