helper.py (1180B)
1 import logging, os.path, traceback 2 import telegram.ext 3 from telegram.ext import Updater, Filters 4 from slackclient import SlackClient 5 6 logger = logging.getLogger(__name__) 7 8 from bot import config 9 10 try: 11 config_class = config.Config(os.path.join('config', 'config.json')) 12 except ValueError: 13 logging.exception("failed to load config, malformed json") 14 sys.exit() 15 16 try: 17 memory_class = config.Memory(os.path.join('config', 'memory.json')) 18 except ValueError: 19 logging.exception("failed to load config, malformed json") 20 sys.exit() 21 22 try: 23 sl_api_key = config_class.get_by_path(['SLACK_API_KEY']) 24 sc = SlackClient(sl_api_key) 25 except Exception as e: 26 traceback.print_exc() 27 28 if os.path.isfile(os.path.join('config', 'memory.json')): 29 try: 30 tg_api_key = config_class.get_by_path(['TELEGRAM_API_KEY']) 31 if not memory_class.exists(['tg_sl-sync']): 32 logger.warn('tg_sl-sync missing...') 33 memory_class.set_by_path(['tg_sl-sync'], {'sl2tg':{}, 'tg2sl': {}}) 34 memory_class.save() 35 tg_bot = telegram.Bot(tg_api_key) 36 updater = Updater(tg_api_key) 37 except Exception as e: 38 traceback.print_exc()