def main(): reload(sys) sys.setdefaultencoding('utf8') config_path = "slackov.cfg" config_default = "slacktoken,\n" \ "slackid,\n" \ "avatarsource,\n" \ "twitterconsumerkey,\n" \ "twitterconsumersecret,\n" \ "twitteraccesstoken,\n" \ "twitteraccesssecret,\n" \ "twitterid," if os.path.isfile(config_path): config_vals = {} config_file = open(config_path, 'r') for line in config_file: try: (key, val) = line.split(',') if key: key = key.strip() if val: val = val.strip() config_vals[key] = val except ValueError: error_message = "Config file not properly setup. " \ "Config: {} missing {} value.\n" print error_message.format(config_path, line.replace(':', '')) slack = { "token": config_vals['slacktoken'], "id": config_vals['slackid'], "avatarsource": config_vals['avatarsource'] } twitter = { "consumer_key": config_vals['twitterconsumerkey'], "consumer_secret": config_vals['twitterconsumersecret'], "access_token": config_vals['twitteraccesstoken'], "access_token_secret": config_vals['twitteraccesssecret'], "id": config_vals['twitterid'] } if None in (slack['token'], slack['id'], slack['avatarsource']): print "Config file not properly setup. " \ "Config file located at {}.\n".format(config_path) else: bot = MarkovBot(None, slack, twitter) bot.start() bot.process.join() print threading.enumerate() else: print "Could not find a config file. " \ "Creating a new one: {}\n".format(config_path) config_file = open(config_path, 'a') config_file.write(config_default) config_file.close()
import threading import os.path config_path = "slackov.cfg" config_default = "token,\nid,\navatarsource," if os.path.isfile(config_path): config_vals = dict() config_file = open(config_path, 'r') for line in config_file: try: (key, val) = line.split(',') config_vals[key] = val except ValueError as e: print "Config file not properly setup. Config: {} missing {} value.\n".format(config_path, line.replace(':','')) if None in (config_vals['token'], config_vals['id'], config_vals['avatarsource']): print "Config file not properly setup. Config file located at {}.\n".format(config_path) else: bot = MarkovBot(config_vals['token'].strip(), None, config_vals['id'].strip(), config_vals['avatarsource'].strip()) bot.start() bot.process.join() print threading.enumerate() else: print "Could not find a config file. Creating a new one: {}\n".format(config_path) config_file = open(config_path, 'a') config_file.write(config_default) config_file.close()
from MarkovBot import MarkovBot import time token = "your-token-here" id = "bot-id" bot = MarkovBot(token, None, id) bot.start()