Ejemplo n.º 1
0
    def __init__(self, test=False, self_checks=True, init_reddit=True, init_coins=True, init_exchanges=True, init_db=True, init_logging=True):
        """
        Constructor. Parses configuration file and initializes bot.
        """
        #self.test = test
        self.test = True #TESTING

        lg.info("CointipBot::__init__()...")
        if self.test:
            lg.info("Running in testing mode. Conf files in test_conf. Logs to test_*.Connecting to a simulated Reddit. Writing to test_db")
            lg.info("Testing mode is primarily to run without Reddit.")

        # Configuration
        self.conf = self.parse_config()

        # Logging
        if init_logging:
            self.init_logging()

        # Templating with jinja2
        self.jenv = Environment(trim_blocks=True, loader=PackageLoader('cointipbot', 'tpl/jinja2'))

        # Database
        if init_db:
            self.db = self.connect_db()

        # Coins
        if init_coins:
            for c in vars(self.conf.coins):
                if self.conf.coins[c].enabled:
                    self.coins[c] = ctb_coin.CtbCoin(_conf=self.conf.coins[c])
            if not len(self.coins) > 0:
                lg.error("CointipBot::__init__(): Error: please enable at least one type of coin")
                sys.exit(1)

        # Exchanges
        if init_exchanges:
            for e in vars(self.conf.exchanges):
                if self.conf.exchanges[e].enabled:
                    self.exchanges[e] = ctb_exchange.CtbExchange(_conf=self.conf.exchanges[e])
            if not len(self.exchanges) > 0:
                lg.warning("Cointipbot::__init__(): Warning: no exchanges are enabled")

        # Reddit
        if init_reddit:
            self.reddit = self.connect_reddit()
            #self.init_subreddits() #not needed if only /u/?
            # Regex for Reddit messages
            ctb_action.init_regex(self)

        # Self-checks (all local checks)
        if self_checks:
            self.self_checks()

        lg.info("< CointipBot::__init__(): DONE, batch-limit = %s, sleep-seconds = %s", self.conf.reddit.scan.batch_limit, self.conf.misc.times.sleep_seconds)
Ejemplo n.º 2
0
    def __init__(self, self_checks=True, init_reddit=True, init_coins=True, init_exchanges=True, init_db=True, init_logging=True):
        """
        Constructor. Parses configuration file and initializes bot.
        """
        lg.info("CointipBot::__init__()...")

        # Configuration
        self.conf = self.parse_config()

        # Logging
        if init_logging:
            self.init_logging()

        # Templating with jinja2
        self.jenv = Environment(trim_blocks=True, loader=PackageLoader('cointipbot', 'tpl/jinja2'))

        # Database
        if init_db:
            self.db = self.connect_db()

        # Coins
        if init_coins:
            for c in vars(self.conf.coins):
                if self.conf.coins[c].enabled:
                    self.coins[c] = ctb_coin.CtbCoin(_conf=self.conf.coins[c])
            if not len(self.coins) > 0:
                lg.error("CointipBot::__init__(): Error: please enable at least one type of coin")
                sys.exit(1)

        # Exchanges
        if init_exchanges:
            for e in vars(self.conf.exchanges):
                if self.conf.exchanges[e].enabled:
                    self.exchanges[e] = ctb_exchange.CtbExchange(_conf=self.conf.exchanges[e])
            if not len(self.exchanges) > 0:
                lg.warning("Cointipbot::__init__(): Warning: no exchanges are enabled")

        # Reddit
        if init_reddit:
            self.reddit = self.connect_reddit()
            self.init_subreddits()
            # Regex for Reddit messages
            ctb_action.init_regex(self)

        # Self-checks
        if self_checks:
            self.self_checks()

        lg.info("< CointipBot::__init__(): DONE, batch-limit = %s, sleep-seconds = %s", self.conf.reddit.scan.batch_limit, self.conf.misc.times.sleep_seconds)
Ejemplo n.º 3
0
# Here's how to add a new coin type to CointipBot

# * Make sure CointipBot instance is NOT running
# * Install and run coin daemon, make sure it's synced with network
# * Configure and nable new coin in config.yml
# * Then run this script, specifying coin (such as "python _add_coin.py btc")
# * After this script has finished, you can reusme the tip bot normally

import cointipbot, logging, sys
from ctb import ctb_coin, ctb_misc

if not len(sys.argv) == 2:
    print "Usage: %s COIN" % sys.argv[0]
    print "(COIN refers to ctb.conf[COIN], a hash location in coins.yml)"
    sys.exit(1)

coin = sys.argv[1]

logging.basicConfig()
lg = logging.getLogger('cointipbot')
lg.setLevel(logging.DEBUG)

ctb = cointipbot.CointipBot(self_checks=False,
                            init_reddit=False,
                            init_coins=False,
                            init_exchanges=False,
                            init_db=True,
                            init_logging=True)
ctb.coins[coin] = ctb_coin.CtbCoin(_conf=ctb.conf.coins[coin])
ctb_misc.add_coin(coin, ctb.db, ctb.coins)
Ejemplo n.º 4
0
    def __init__(self, self_checks=True, init_coins=True, init_db=True, init_logging=True, init_exchanges=True,
                 init_reddit=False, init_twitter=False, init_twitch=False, init_irc=False):
        """
        Constructor. Parses configuration file and initializes bot.
        """
        lg.info("CointipBot::__init__()...")

        # Configuration
        self.conf = self.parse_config()

        # Logging
        if init_logging:
            self.init_logging()

        # Database
        if init_db:
            self.db = self.connect_db()

        # Coins
        if init_coins:
            for c in vars(self.conf.coins):
                if self.conf.coins[c].enabled:
                    self.coins[c] = ctb_coin.CtbCoin(_conf=self.conf.coins[c])
            if not len(self.coins) > 0:
                lg.error("CointipBot::__init__(): Error: please enable at least one type of coin")
                sys.exit(1)

        # Networks
        if init_reddit:
            self.conf.network = self.conf.reddit.reddit
            self.conf.regex = self.conf.reddit.regex
            self.network = RedditNetwork(self.conf.network, self)
        elif init_twitter:
            self.conf.network = self.conf.twitter.twitter
            self.conf.regex = self.conf.twitter.regex
            self.network = TwitterNetwork(self.conf.network, self)
        elif init_twitch:
            self.conf.network = self.conf.twitch.twitch
            self.conf.regex = self.conf.twitch.regex
            self.network = TwitchNetwork(self.conf.network, self)
        elif init_irc:
            self.conf.network = self.conf.irc.irc
            self.conf.regex = self.conf.irc.regex
            self.network = IRCNetwork(self.conf.network, self)

        ctb_action.init_regex(self)
        self.network.connect()
        self.network.init()

        # Exchanges
        if init_exchanges:
            for e in vars(self.conf.exchanges):
                if self.conf.exchanges[e].enabled:
                    self.exchanges[e] = ctb_exchange.CtbExchange(_conf=self.conf.exchanges[e])
            if not len(self.exchanges) > 0:
                lg.warning("Cointipbot::__init__(): Warning: no exchanges are enabled")

        # Template
        self.jenv = Environment(trim_blocks=True, loader=PackageLoader('cointipbot', 'tpl/' + self.network.name))

        # Self-checks
        if self_checks:
           self.self_checks()

        lg.info("< CointipBot::__init__(): DONE, sleep-seconds = %s", self.conf.misc.times.sleep_seconds)