From e2c62f007d5d847611d3cb23d2f4ed93e3f4e005 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Fri, 24 Jul 2020 13:26:02 +0200 Subject: Non-existent jsons are now created on run --- main.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'main.py') diff --git a/main.py b/main.py index 13bc0f0..28b58ab 100755 --- a/main.py +++ b/main.py @@ -6,6 +6,26 @@ from colorama import init as init_colorama from bot import BedrockBot +def check_jsons(): + try: + f = open('config.json', 'r') + except FileNotFoundError: + token = input('BOT SETUP - Enter bot token: ') + with open('config.json', 'w+') as f: + json.dump({"token": token}, f, indent=4) + + try: + f = open('blacklist.json', 'r') + except FileNotFoundError: + with open('blacklist.json', 'w+') as f: + json.dump([], f, indent=4) + + try: + f = open('video_blacklist.json', 'r') + except FileNotFoundError: + with open('video_blacklist.json', 'w+') as f: + json.dump([], f, indent=4) + def setup_logging(): FORMAT = '%(asctime)s - [%(levelname)s]: %(message)s' DATE_FORMAT = '%d/%m/%Y (%H:%M:%S)' @@ -34,4 +54,6 @@ if __name__ == "__main__": setup_logging() + check_jsons() + run_bot() -- cgit v1.2.3 From ffff63790fe5e69c37445b88257b1879ec19ed48 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Fri, 24 Jul 2020 16:17:25 +0200 Subject: Added import --- main.py | 80 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 36 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 28b58ab..3bf6112 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import asyncio import logging +import json from colorama import init as init_colorama @@ -7,53 +8,60 @@ from bot import BedrockBot def check_jsons(): - try: - f = open('config.json', 'r') - except FileNotFoundError: - token = input('BOT SETUP - Enter bot token: ') - with open('config.json', 'w+') as f: - json.dump({"token": token}, f, indent=4) - - try: - f = open('blacklist.json', 'r') - except FileNotFoundError: - with open('blacklist.json', 'w+') as f: - json.dump([], f, indent=4) - - try: - f = open('video_blacklist.json', 'r') - except FileNotFoundError: - with open('video_blacklist.json', 'w+') as f: - json.dump([], f, indent=4) + try: + f = open('config.json', 'r') + except FileNotFoundError: + token = input('BOT SETUP - Enter bot token: ') + with open('config.json', 'w+') as f: + json.dump({"token": token}, f, indent=4) + + try: + f = open('blacklist.json', 'r') + except FileNotFoundError: + with open('blacklist.json', 'w+') as f: + json.dump([], f, indent=4) + + try: + f = open('video_blacklist.json', 'r') + except FileNotFoundError: + with open('video_blacklist.json', 'w+') as f: + json.dump([], f, indent=4) + def setup_logging(): - FORMAT = '%(asctime)s - [%(levelname)s]: %(message)s' - DATE_FORMAT = '%d/%m/%Y (%H:%M:%S)' + FORMAT = '%(asctime)s - [%(levelname)s]: %(message)s' + DATE_FORMAT = '%d/%m/%Y (%H:%M:%S)' + + logger = logging.getLogger('discord') + logger.setLevel(logging.INFO) - logger = logging.getLogger('discord') - logger.setLevel(logging.INFO) + file_handler = logging.FileHandler(filename='discord.log', + mode='a', + encoding='utf-8') + file_handler.setFormatter( + logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)) + file_handler.setLevel(logging.INFO) + logger.addHandler(file_handler) - file_handler = logging.FileHandler(filename='discord.log', mode='a', encoding='utf-8') - file_handler.setFormatter(logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)) - file_handler.setLevel(logging.INFO) - logger.addHandler(file_handler) + console_handler = logging.StreamHandler() + console_handler.setFormatter( + logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)) + console_handler.setLevel(logging.WARNING) + logger.addHandler(console_handler) - console_handler = logging.StreamHandler() - console_handler.setFormatter(logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)) - console_handler.setLevel(logging.WARNING) - logger.addHandler(console_handler) def run_bot(): - bot = BedrockBot() - bot.run() + bot = BedrockBot() + bot.run() + if __name__ == "__main__": - init_colorama(autoreset=True) + init_colorama(autoreset=True) - setup_logging() + setup_logging() - check_jsons() + check_jsons() - run_bot() + run_bot() -- cgit v1.2.3