Ejemplo n.º 1
0
def main():
    import argparse

    from nicelogger import enable_pretty_logging

    parser = argparse.ArgumentParser(
        description='HTTP services for build.archlinuxcn.org', )
    parser.add_argument('--port',
                        default=9007,
                        type=int,
                        help='port to listen on')
    parser.add_argument('--ip',
                        default='127.0.0.1',
                        help='address to listen on')
    parser.add_argument('--loglevel',
                        default='info',
                        choices=['debug', 'info', 'warn', 'error'],
                        help='log level')
    args = parser.parse_args()

    enable_pretty_logging(args.loglevel.upper())

    app = web.Application()
    setup_app(app, os.environ['SECRET'], os.environ['GITHUB_TOKEN'])

    web.run_app(app, host=args.ip, port=args.port)
Ejemplo n.º 2
0
def main(urls, # *, commented for Python 2
         url_finders=None):
  from .extrafinders import GithubFinder
  if not url_finders:
    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

  try:
    from nicelogger import enable_pretty_logging
  except ImportError:
    from tornado.log import enable_pretty_logging
  enable_pretty_logging()

  f = BatchFetcher()
  for u in urls:
    f.add(u)
  tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 3
0
def single_main(build_prefix='makepkg'):
    prepend_self_path()
    enable_pretty_logging('DEBUG')
    lilac_build(
        build_prefix=build_prefix,
        accept_noupdate=True,
    )
Ejemplo n.º 4
0
async def main(urls, *, url_finders=None):
  fixup()

  from .extrafinders import GithubFinder, GithubUserFinder, ZhihuZhuanlan, NeteaseMusic
  if not url_finders:
    url_finders = (GithubFinder, GithubUserFinder, ZhihuZhuanlan, NeteaseMusic)

  try:
    from nicelogger import enable_pretty_logging
    enable_pretty_logging()
  except ImportError:
    pass

  futures = [
    TitleFetcher(url, url_finders=url_finders).run()
    for url in urls
  ]
  for fu in asyncio.as_completed(futures):
    try:
      result = await fu
    except Exception:
      logger.exception('an error occurred')
      continue

    info = result.info
    urls = result.url_visited
    status_code = result.status_code

    url = ' <- '.join(reversed(urls))
    logger.info('done: [%d] %s <- %s',
                status_code, info, url)
Ejemplo n.º 5
0
def single_main(build_prefix='makepkg'):
    prepend_self_path()
    enable_pretty_logging('DEBUG')
    with lilacpy.load_lilac(Path('.')) as mod:
        lilac_build(
            mod,
            build_prefix=build_prefix,
            accept_noupdate=True,
        )
Ejemplo n.º 6
0
def single_main(build_prefix='makepkg'):
  prepend_self_path()
  enable_pretty_logging('DEBUG')
  lilac_build(
    build_prefix = build_prefix,
    repodir = os.path.dirname(
      os.path.dirname(sys.modules['__main__'].__file__)),
    accept_noupdate = True,
  )
Ejemplo n.º 7
0
def single_main(build_prefix='makepkg'):
    prepend_self_path()
    enable_pretty_logging('DEBUG')
    lilac_build(
        build_prefix=build_prefix,
        repodir=os.path.dirname(
            os.path.dirname(sys.modules['__main__'].__file__)),
        accept_noupdate=True,
    )
Ejemplo n.º 8
0
def single_main(build_prefix='makepkg'):
  prepend_self_path()
  enable_pretty_logging('DEBUG')
  with lilacpy.load_lilac(Path('.')) as mod:
    lilac_build(
      mod,
      build_prefix = build_prefix,
      accept_noupdate = True,
    )
Ejemplo n.º 9
0
Archivo: api.py Proyecto: zsrkmyn/lilac
def single_main(build_prefix: str = 'makepkg') -> None:
  from nicelogger import enable_pretty_logging
  from . import lilacpy
  from .building import lilac_build

  _prepend_self_path()
  enable_pretty_logging('DEBUG')
  with lilacpy.load_lilac(Path('.')) as mod:
    lilac_build(
      mod,
      build_prefix = build_prefix,
      accept_noupdate = True,
    )
Ejemplo n.º 10
0
Archivo: api.py Proyecto: VOID001/lilac
def single_main(build_prefix: str = 'makepkg') -> None:
    from nicelogger import enable_pretty_logging
    from . import lilacpy
    from .building import lilac_build

    _prepend_self_path()
    enable_pretty_logging('DEBUG')
    with lilacpy.load_lilac(Path('.')) as mod:
        lilac_build(
            mod,
            build_prefix=build_prefix,
            accept_noupdate=True,
        )
Ejemplo n.º 11
0
def main(
        urls,  # *, commented for Python 2
        url_finders=None):
    from .extrafinders import GithubFinder, GithubUserFinder
    if not url_finders:
        url_finders = (GithubFinder, GithubUserFinder)

    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

    try:
        from nicelogger import enable_pretty_logging
    except ImportError:
        from tornado.log import enable_pretty_logging
    enable_pretty_logging()

    f = BatchFetcher()
    for u in urls:
        f.add(u)
    tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 12
0
  )

if __name__ == '__main__':
  import argparse
  from nicelogger import enable_pretty_logging

  parser = argparse.ArgumentParser(
    description='A bot bridging minecraft and telegram group')
  parser.add_argument('-c', '--config', required=True,
                      help='configuration file')
  parser.add_argument('--pidfile',
                      help='pidfile to write pid to')
  parser.add_argument('--loglevel', default='info',
                      choices=['debug', 'info', 'warn', 'error'],
                      help='log level')
  args = parser.parse_args()

  enable_pretty_logging(args.loglevel.upper())

  with open(args.config) as f:
    config = toml.load(f)

  if args.pidfile:
    with open(args.pidfile, 'w') as f:
      print(os.getpid(), file=f)

  try:
    asyncio.run(main(config))
  except KeyboardInterrupt:
    pass
Ejemplo n.º 13
0
def main():
  import os
  from getpass import getpass
  import argparse
  from nicelogger 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()
Ejemplo n.º 14
0
class ZhihuTopic(base.BaseHandler):
    async def get(self, id):
        """
    :param id (str): Zhihu topic id, as "19551894" in "https://www.zhihu.com/topic/19551894/hot"
    :return: Future with RSS content
    """
        if id.endswith(' '):
            raise web.HTTPError(404)
        sort = self.get_argument('sort', None)
        # invalid sort param
        if sort not in ('newest', 'hot'):
            # Sort by popularity by default
            sort = 'hot'
        pic = self.get_argument('pic', None)
        rss = await topic2rss(id, sort=sort, pic=pic)
        self.finish(rss)


async def test():
    # rss = await activities2rss('cai-qian-hua-56')
    rss = await activities2rss('farseerfc')
    print(rss)


if __name__ == '__main__':
    import tornado.ioloop
    from nicelogger import enable_pretty_logging
    enable_pretty_logging('DEBUG')
    loop = tornado.ioloop.IOLoop.current()
    loop.run_sync(test)
Ejemplo n.º 15
0
def main():
    import os
    from getpass import getpass
    import argparse
    from nicelogger 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()
Ejemplo n.º 16
0
    return item


class ZhihuStream(base.BaseHandler):
    @gen.coroutine
    def get(self, name):
        pic = self.get_argument('pic', None)
        digest = self.get_argument('digest', False) == 'true'

        try:
            rss = yield activities2rss(name, digest=digest, pic=pic)
        except tornado.httpclient.HTTPError as e:
            if e.code in [404, 429]:
                raise web.HTTPError(e.code)
            else:
                raise
        self.finish(rss)


async def test():
    rss = await activities2rss('cai-qian-hua-56')
    print(rss)


if __name__ == '__main__':
    import tornado.ioloop
    from nicelogger import enable_pretty_logging
    enable_pretty_logging('INFO')
    loop = tornado.ioloop.IOLoop.current()
    loop.run_sync(test)
Ejemplo n.º 17
0
    pubDate = pub_date,
    author = post['author']['name'],
  )
  return item

class ZhihuStream(base.BaseHandler):
  @gen.coroutine
  def get(self, name):
    pic = self.get_argument('pic', None)
    digest = self.get_argument('digest', False) == 'true'

    try:
      rss = yield activities2rss(name, digest=digest, pic=pic)
    except tornado.httpclient.HTTPError as e:
      if e.code in [404, 429]:
        raise web.HTTPError(e.code)
      else:
        raise
    self.finish(rss)

async def test():
  rss = await activities2rss('cai-qian-hua-56')
  print(rss)

if __name__ == '__main__':
  import tornado.ioloop
  from nicelogger import enable_pretty_logging
  enable_pretty_logging('INFO')
  loop = tornado.ioloop.IOLoop.current()
  loop.run_sync(test)