Exemplo n.º 1
0
def main(urls):
  class BatchFetcher:
    n = 0
    def __call__(self, title, fetcher):
      if isinstance(title, bytes):
        try:
          title = title.decode('gb18030')
        except UnicodeDecodeError:
          pass
      url = ' <- '.join(reversed(fetcher.url_visited))
      logger.info('done: [%d] %s <- %s' % (fetcher.status_code, title, url))
      self.n -= 1
      if not self.n:
        tornado.ioloop.IOLoop.instance().stop()

    def add(self, url):
      TitleFetcher(url, self, url_finders=(GithubFinder,))
      self.n += 1

  from myutils import enable_pretty_logging
  enable_pretty_logging()
  f = BatchFetcher()
  for u in urls:
    f.add(u)
  tornado.ioloop.IOLoop.instance().start()
Exemplo n.º 2
0
def main(urls):
  class BatchFetcher:
    n = 0
    def __call__(self, title, fetcher):
      if isinstance(title, bytes):
        try:
          title = title.decode('gb18030')
        except UnicodeDecodeError:
          pass
      if fetcher.origurl == fetcher.fullurl:
        url = fetcher.origurl
      else:
        url = fetcher.fullurl + ' <- ' + fetcher.origurl
      logger.info('done: [%d] %s <- %s' % (fetcher.status_code, title, url))
      self.n -= 1
      if not self.n:
        tornado.ioloop.IOLoop.instance().stop()

    def add(self, url):
      TitleFetcher(url, self)
      self.n += 1

  from myutils import enable_pretty_logging
  enable_pretty_logging()
  f = BatchFetcher()
  for u in urls:
    f.add(u)
  tornado.ioloop.IOLoop.instance().start()
Exemplo n.º 3
0
def main(urls, url_finders=(GithubFinder, )):
    class BatchFetcher:
        n = 0

        def __call__(self, title, fetcher):
            if isinstance(title, bytes):
                try:
                    title = title.decode('gb18030')
                except UnicodeDecodeError:
                    pass
            url = ' <- '.join(reversed(fetcher.url_visited))
            logger.info('done: [%d] %s <- %s' %
                        (fetcher.status_code, title, url))
            self.n -= 1
            if not self.n:
                tornado.ioloop.IOLoop.instance().stop()

        def add(self, url):
            TitleFetcher(url, self, url_finders=url_finders)
            self.n += 1

    from myutils import enable_pretty_logging
    enable_pretty_logging()
    f = BatchFetcher()
    for u in urls:
        f.add(u)
    tornado.ioloop.IOLoop.instance().start()
Exemplo n.º 4
0
#!/usr/bin/env python3
# vim:fileencoding=utf-8

import os
import sys
import time
import configparser
import subprocess
import logging
import shutil
import tarfile

from myutils import enable_pretty_logging
enable_pretty_logging(logging.DEBUG)

class Command:
  def __init__(self, ctx, args):
    self.args = args
    self.ctx = ctx
    self.run()

class WaitCommand(Command):
  cmd = 'wait'
  def run(self):
    t = self.ctx['wait_time'] + 2
    logging.info('waiting for %d seconds...', t)
    time.sleep(t)

class BaseDirCommand(Command):
  cmd = 'base_dir'
  def run(self):
Exemplo n.º 5
0
def main():
  import os
  from getpass import getpass
  import argparse
  from myutils import enable_pretty_logging
  from cli import repl

  """Parse the command-line arguments and run the bot."""
  parser = argparse.ArgumentParser(description = 'XMPP dev bot',
                  parents = [XMPPSettings.get_arg_parser()])
  parser.add_argument('jid', metavar = 'JID',
                    help = 'The bot JID')
  parser.add_argument('--debug',
            action = 'store_const', dest = 'log_level',
            const = logging.DEBUG, default = logging.INFO,
            help = 'Print debug messages')
  parser.add_argument('--quiet', const = logging.ERROR,
            action = 'store_const', dest = 'log_level',
            help = 'Print only error messages')
  parser.add_argument('--trace', action = 'store_true',
            help = 'Print XML data sent and received')

  args = parser.parse_args()
  settings = XMPPSettings({
    "software_name": "pyxmpp2 Bot"
  })
  settings.load_arguments(args)
  if args.jid.endswith('@gmail.com'):
    settings['starttls'] = True
    settings['tls_verify_peer'] = False

  if settings.get("password") is None:
    password = getpass("{0!r} password: "******"password"] = password

  if args.trace:
    logging.info('enabling trace')
    for logger in ("pyxmpp2.IN", "pyxmpp2.OUT"):
      logger = logging.getLogger(logger)
      logger.setLevel(logging.DEBUG)
  enable_pretty_logging(level=args.log_level)

  bot = AutoAcceptBot(JID(args.jid), settings)

  class Q:
    def __call__(self):
      sys.exit()
    __repr__ = __call__

  q = Q()
  self = bot

  try:
    bot.connect()
    while True:
      try:
        bot.run()
      except KeyboardInterrupt:
        v = vars()
        v.update(globals())
        repl(v, os.path.expanduser('~/.xmppbot_history'))
  except SystemExit:
    bot.disconnect()
  except:
    bot.disconnect()
    import traceback
    traceback.print_exc()
Exemplo n.º 6
0
def main():
  import os
  from getpass import getpass
  import argparse
  from myutils import enable_pretty_logging
  from cli import repl

  """Parse the command-line arguments and run the bot."""
  parser = argparse.ArgumentParser(description = 'XMPP echo bot',
                  parents = [XMPPSettings.get_arg_parser()])
  parser.add_argument('jid', metavar = 'JID',
                    help = 'The bot JID')
  parser.add_argument('--debug',
            action = 'store_const', dest = 'log_level',
            const = logging.DEBUG, default = logging.INFO,
            help = 'Print debug messages')
  parser.add_argument('--quiet', const = logging.ERROR,
            action = 'store_const', dest = 'log_level',
            help = 'Print only error messages')
  parser.add_argument('--trace', action = 'store_true',
            help = 'Print XML data sent and received')

  args = parser.parse_args()
  settings = XMPPSettings({
    "software_name": "pyxmpp2 Bot"
  })
  settings.load_arguments(args)
  if args.jid.endswith('@gmail.com'):
    settings['starttls'] = True
    settings['tls_verify_peer'] = False

  if settings.get("password") is None:
    password = getpass("{0!r} password: "******"password"] = password

  if args.trace:
    logging.info('enabling trace')
    for logger in ("pyxmpp2.IN", "pyxmpp2.OUT"):
      logger = logging.getLogger(logger)
      logger.setLevel(logging.DEBUG)

  enable_pretty_logging(level=args.log_level)
  root = logging.getLogger()
  root.handlers[0].setFormatter(root.handlers[1].formatter)
  del root.handlers[1]
  del root

  bot = AutoAcceptBot(JID(args.jid), settings)

  q = sys.exit
  self = bot

  try:
    bot.connect()
    while True:
      try:
        bot.run()
      except KeyboardInterrupt:
        v = vars()
        v.update(globals())
        repl(v, os.path.expanduser('~/.xmppbot_history'))
  except SystemExit:
    bot.disconnect()
  except:
    bot.disconnect()
    import traceback
    traceback.print_exc()
Exemplo n.º 7
0
def main():
    import os
    from getpass import getpass
    import argparse
    from myutils import enable_pretty_logging
    from cli import repl

    """Parse the command-line arguments and run the bot."""
    parser = argparse.ArgumentParser(description="XMPP dev bot", parents=[XMPPSettings.get_arg_parser()])
    parser.add_argument("jid", metavar="JID", help="The bot JID")
    parser.add_argument(
        "--debug",
        action="store_const",
        dest="log_level",
        const=logging.DEBUG,
        default=logging.INFO,
        help="Print debug messages",
    )
    parser.add_argument(
        "--quiet", const=logging.ERROR, action="store_const", dest="log_level", help="Print only error messages"
    )
    parser.add_argument("--trace", action="store_true", help="Print XML data sent and received")

    args = parser.parse_args()
    settings = XMPPSettings({"software_name": "pyxmpp2 Bot"})
    settings.load_arguments(args)
    if args.jid.endswith("@gmail.com"):
        settings["starttls"] = True
        settings["tls_verify_peer"] = False

    if settings.get("password") is None:
        password = getpass("{0!r} password: "******"password"] = password

    if args.trace:
        logging.info("enabling trace")
        for logger in ("pyxmpp2.IN", "pyxmpp2.OUT"):
            logger = logging.getLogger(logger)
            logger.setLevel(logging.DEBUG)
    enable_pretty_logging(level=args.log_level)

    bot = AutoAcceptBot(JID(args.jid), settings)

    class Q:
        def __call__(self):
            sys.exit()

        __repr__ = __call__

    q = Q()
    self = bot

    try:
        bot.connect()
        while True:
            try:
                bot.run()
            except KeyboardInterrupt:
                v = vars()
                v.update(globals())
                repl(v, os.path.expanduser("~/.xmppbot_history"))
    except SystemExit:
        bot.disconnect()
    except:
        bot.disconnect()
        import traceback

        traceback.print_exc()
Exemplo n.º 8
0
#!/usr/bin/env python3
# vim:fileencoding=utf-8

import os
import sys
import time
import configparser
import subprocess
import logging
import shutil
import tarfile

from myutils import enable_pretty_logging
enable_pretty_logging(logging.DEBUG)


class Command:
    def __init__(self, ctx, args):
        self.args = args
        self.ctx = ctx
        self.run()


class WaitCommand(Command):
    cmd = 'wait'

    def run(self):
        t = self.ctx['wait_time'] + 2
        logging.info('waiting for %d seconds...', t)
        time.sleep(t)