commit a11cb1a5f0de9ca6188bce58ba60c6fb5d26d21d
parent df4901fad1cd5f598ef0a2d9e74f8dfa909fb6ed
Author: Marcel Radzio <mtrnord1@gmail.com>
Date: Mon, 20 Feb 2017 21:38:01 +0100
some linux related fixes
Diffstat:
| M | bot.py | | | 73 | ++++++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 34 insertions(+), 39 deletions(-)
diff --git a/bot.py b/bot.py
@@ -4,11 +4,42 @@ from multiprocessing import Pool
logger = logging.getLogger(__name__)
-#Import internal Modules that are needed
-from bot import Htelegram
-from bot import Hslack
from bot.helper import config_class
+if __name__ == "__main__":
+ default_log_path = os.path.join('config', 'TG-SL_bot.log')
+
+ parser = argparse.ArgumentParser(prog='TG-SL_bot',
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('--log', default=default_log_path,
+ help='log file path')
+ parser.add_argument('-d', '--debug', action='store_true',
+ help='log detailed debugging messages')
+ args = parser.parse_args()
+
+ if os.path.isdir("config"):
+ if not (config_class.get_by_path(['SLACK_API_KEY'])) or (config_class.get_by_path(['TELEGRAM_API_KEY'])):
+ sys.exit('Please set Api Keys')
+ #Import internal Modules that are needed
+ from bot import Htelegram
+ from bot import Hslack
+ else:
+ os.makedirs("config")
+ if not os.path.isfile(os.path.join('config', 'config.json')):
+ try:
+ shutil.copy(os.path.join('defaults', 'config.json'), os.path.join('config', 'config.json'))
+ except (OSError, IOError) as e:
+ sys.exit('Failed to copy default config file: {}'.format(e))
+ if not os.path.isfile(os.path.join('config', 'memory.json')):
+ try:
+ shutil.copy(os.path.join('defaults', 'memory.json'), os.path.join('config', 'memory.json'))
+ except (OSError, IOError) as e:
+ sys.exit('Failed to copy default memory file: {}'.format(e))
+
+ configure_logging(args)
+ core = Core()
+ core.run()
+
class Core:
def run(self):
pool = Pool(2)
@@ -99,39 +130,3 @@ def configure_logging(args):
logger = logging.getLogger()
if args.debug:
logger.setLevel(logging.DEBUG)
-
-if __name__ == "__main__":
- default_log_path = os.path.join('config', 'TG-SL_bot.log')
-
- parser = argparse.ArgumentParser(prog='TG-SL_bot',
- formatter_class=argparse.ArgumentDefaultsHelpFormatter)
- parser.add_argument('--log', default=default_log_path,
- help='log file path')
- parser.add_argument('-d', '--debug', action='store_true',
- help='log detailed debugging messages')
- args = parser.parse_args()
-
- if os.path.isdir("config"):
- if not os.path.isfile(os.path.join('config', 'config.json')):
- try:
- shutil.copy(os.path.join('config', 'config.json'), os.path.join('config', 'config.json'))
- sys.exit('Please set Api Keys')
- except (OSError, IOError) as e:
- sys.exit('Failed to copy default config file: {}'.format(e))
- if not os.path.isfile(os.path.join('config', 'config.json')):
- try:
- shutil.copy(os.path.join('defaults', 'memory.json'), os.path.join('config', 'memory.json'))
- except (OSError, IOError) as e:
- sys.exit('Failed to copy default memory file: {}'.format(e))
- else:
- os.makedirs("config")
- if not os.path.isfile(os.path.join('config', 'config.json')):
- try:
- shutil.copy(os.path.join('defaults', 'config.json'), os.path.join('config', 'config.json'))
- sys.exit('Please set Api Keys')
- except (OSError, IOError) as e:
- sys.exit('Failed to copy default config file: {}'.format(e))
-
- configure_logging(args)
- core = Core()
- core.run()