Exemplo n.º 1
0
    def init(self):
        self.say(["notice", "-== "], ["error", "Welcome to Aires!"], ["notice", " ==-"])

        # TODO: load core config files

        # Load bot config files.
        self.say(["error", "== "], ["notice", "Reading chatterbot settings"], ["error", " =="])
        for cfg in config.list("bots"):
            self.say(["error", ":: "], "Read: %s" % cfg)
            bot = re.sub(r"\.json$", "", cfg)
            self._bots[bot] = config.read("bots/" + cfg)

        # Initialize the brains.
        self.say(["error", "== "], ["notice", "Initializing chatterbot brains"], ["error", " =="])
        for bot in sorted(self._bots):
            brain = self._bots[bot]["brain"]["name"]
            args = self._bots[bot]["brain"]["args"]
            self.say(["error", ":: "], 'Loading brain "%s" for bot "%s"' % (brain, bot))

            # Dynamically import and load the brain.
            cls = self._dyn_import("aires.brains." + brain, brain)
            self._brains[bot] = cls(self, args)

        # Initialize the listeners.
        self.say(["error", "== "], ["notice", "Initializing chatterbot listeners (mirrors)"], ["error", " =="])
        for bot in sorted(self._bots):
            for listener, largs in self._bots[bot]["listeners"].iteritems():
                # Skip inactive listeners.
                if largs["active"] != True:
                    continue

                # Import the listener module.
                cls = self._dyn_import("aires.listeners." + listener, listener)

                # Initialize all the mirrors.
                for mirror in largs["mirrors"]:
                    username = mirror["username"]
                    uid = self.format_name(listener, username)
                    self.say("\tCreating mirror: " + uid)

                    # Map the agent name to the bot.
                    self._agents[uid] = bot

                    # Initialize the listener for this mirror.
                    self._mirrors[uid] = cls(self, uid, bot, mirror)
                    self._mirrors[uid].handlers()

                    # Does this mirror use Twisted?
                    if self._mirrors[uid].is_twisted():
                        self._twisted = True
def config(
        view, 
        edit, 
        clear
):
    """"""
    first = True

    if clear:
        if click.confirm("Are you sure you want to clear your PRAW configuration values?"):
            cfg.clear()
            click.echo("Cleared PRAW configuration values.")
        else:
            click.echo("PRAW configuration values were not cleared.")
        first = False
    
    if edit:
        if first:
            first = False
        else:
            click.echo()
        # TODO: check if config values are valid
        cfg.edit(edit[0], edit[1], edit[2])
        click.echo("PRAW configuration values were set.")
    
    if view:
        if first:
            first = False
        else:
            click.echo()
        values = cfg.list()
        click.echo("Client ID")
        secho_yellow("  " + values['client_id'], True)
        click.echo("Client Secret")
        secho_yellow("  " + values['client_secret'], True)
        click.echo("User Agent")
        secho_yellow("  " + values['user_agent'], True)
Exemplo n.º 3
0
def main(argv=[]):
  args = parser.get_parser()

  verbose = 1
  if args.verbose:
    verbose = 2
  if args.debug:
    verbose = 3

  if verbose>2:
    log_level=logging.DEBUG
  elif verbose==2:
    log_level=logging.INFO
  elif verbose==1:
    log_level=logging.WARNING
  elif verbose<1:
    log_level=logging.ERROR

  logging.basicConfig(level=log_level, format="%(asctime)s %(levelname)s: %(message)s")

  if args.command == 'version':
    print cexbot.get_version()
    return True

  # make sure this is always above command parsing
  # print config
  config.first_run()

  if verbose == 3:
    print args

  if args.command == 'config':
    if args.list:
      return config.list()
    elif args.edit:
      return config.edit_config()
    elif args.testauth:
      return config.test_auth()
    elif args.name and args.value:
      v = config.set(args.name, args.value)
      return config.cprint(args.name)
    elif args.name:
      return config.cprint(args.name)
    logging.error('Invalid config option')
    return 1

  elif args.command == 'update':
    return updater.check_update()

  # not implemented
  elif args.command == 'cleardata':
    return config.clear_userdata()


  ac = cexapi.CexAPI(config.get('cex.username'), config.get('cex.apikey'), config.get('cex.secret'))
  dbi = db.DbManager()
  cx = CexMethods(ac, dbi)

  if args.command == 'balance':
    print "Balance: %s BTC" % ac.get_balance()
    return True

  elif args.command == 'initdb':
    return dbi.initdb()

  elif args.command == 'getmarket':
    return ac.get_market()

  elif args.command == 'getprice':
    return ac.get_market_quote()

  elif args.command == 'order':
    amount = args.amount
    price = args.price
    r = ac.place_order(amount, price)
    logging.info("Ordered: %s" % r)

  elif args.command == 'updatequotes':
    logging.info('Running updatequotes')
    ticker_timer = timer.ReqTimer(2, cx.update_ticker)
    ticker_timer.start()

  elif args.command == 'buybalance':
    logging.info('Running buybalance')
    balance_timer = timer.ReqTimer(5, ac.buy_balance)
    balance_timer.start()
Exemplo n.º 4
0
    def init(self):
        self.say(
            ['notice', '-== '],
            ['error', 'Welcome to Aires!'],
            ['notice', ' ==-'],
        )

        # TODO: load core config files

        # Load bot config files.
        self.say(
            ['error', '== '],
            ['notice', 'Reading chatterbot settings'],
            ['error', ' =='],
        )
        for cfg in config.list('bots'):
            self.say(
                ['error', ':: '],
                "Read: %s" % cfg,
            )
            bot = re.sub(r'\.json$', '', cfg)
            self._bots[bot] = config.read('bots/' + cfg)

        # Initialize the brains.
        self.say(
            ['error', '== '],
            ['notice', 'Initializing chatterbot brains'],
            ['error', ' =='],
        )
        for bot in sorted(self._bots):
            brain = self._bots[bot]['brain']['name']
            args = self._bots[bot]['brain']['args']
            self.say(['error', ':: '],
                     'Loading brain "%s" for bot "%s"' % (brain, bot))

            # Dynamically import and load the brain.
            cls = self._dyn_import('aires.brains.' + brain, brain)
            self._brains[bot] = cls(self, args)

        # Initialize the listeners.
        self.say(
            ['error', '== '],
            ['notice', 'Initializing chatterbot listeners (mirrors)'],
            ['error', ' =='],
        )
        for bot in sorted(self._bots):
            for listener, largs in self._bots[bot]['listeners'].iteritems():
                # Skip inactive listeners.
                if largs['active'] != True:
                    continue

                # Import the listener module.
                cls = self._dyn_import('aires.listeners.' + listener, listener)

                # Initialize all the mirrors.
                for mirror in largs['mirrors']:
                    username = mirror['username']
                    uid = self.format_name(listener, username)
                    self.say("\tCreating mirror: " + uid)

                    # Map the agent name to the bot.
                    self._agents[uid] = bot

                    # Initialize the listener for this mirror.
                    self._mirrors[uid] = cls(self, uid, bot, mirror)
                    self._mirrors[uid].handlers()

                    # Does this mirror use Twisted?
                    if self._mirrors[uid].is_twisted():
                        self._twisted = True
Exemplo n.º 5
0
import sys
import os

mydir      =  os.path.dirname(os.path.realpath(__file__))
parent_dir = os.path.dirname(mydir)

sys.path.append(parent_dir + '/lib')

import config

file=parent_dir + "/config/config.ini"
config = config.Config(file)
print config.list()
for section in config.list():
    print section + ":"
    section_info = config.get(section)
    for property in section_info:
        print "\t" + property + ": " + section_info[property]
from datetime import datetime, timedelta

import praw

import config
import filters
import submissions
import subreddits

config = config.list()
filters = filters.list()
subreddits = subreddits.list()


def scrape(time):
    reddit = praw.Reddit(client_id=config['client_id'],
                         client_secret=config['client_secret'],
                         user_agent=config['user_agent'])

    submissions.clear()

    min_time = datetime.now() - timedelta(minutes=time)
    for name in subreddits:
        for submission in reddit.subreddit(name).new(limit=None):
            submission_time = datetime.fromtimestamp(submission.created_utc)
            if min_time > submission_time:
                break
            if not filter(name, submission):
                continue
            submissions.add(submission.title, submission.author.name,
                            submission_time, name, submission.link_flair_text,