当前位置: 首页>>代码示例>>Python>>正文


Python Article.cleanup方法代码示例

本文整理汇总了Python中article.Article.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python Article.cleanup方法的具体用法?Python Article.cleanup怎么用?Python Article.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在article.Article的用法示例。


在下文中一共展示了Article.cleanup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: speed_test

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import cleanup [as 别名]
def speed_test(uuid):
    try:
        print("Starting speed test")
        t0 = time.time()
        with SessionContext(commit = True) as session:
            # Load the article
            a = Article.load_from_uuid(uuid, session)
            if a is not None:
                # Parse it and store the updated version
                a.parse(session, verbose = True)
        t1 = time.time()
        print("Parsing finished in {0:.2f} seconds".format(t1 - t0))
    finally:
        Article.cleanup()
开发者ID:vthorsteinsson,项目名称:Reynir,代码行数:16,代码来源:speedtest.py

示例2:

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import cleanup [as 别名]
            extra_files=extra_files,
        )

    except socket_error as e:
        if e.errno == errno.EADDRINUSE:  # Address already in use
            logging.error(
                "Reynir is already running at host {0}:{1}".format(
                    Settings.HOST, Settings.PORT
                )
            )
            sys.exit(1)
        else:
            raise

    finally:
        ArticleProxy.cleanup()
        BIN_Db.cleanup()

else:

    # Suppress information log messages from Werkzeug
    werkzeug_log = logging.getLogger("werkzeug")
    if werkzeug_log:
        werkzeug_log.setLevel(logging.WARNING)

    # Log our startup
    log_str = "Reynir instance starting with host={0}:{1}, db_hostname={2} on Python {3}".format(
        Settings.HOST,
        Settings.PORT,
        Settings.DB_HOSTNAME,
        sys.version.replace("\n", " "),
开发者ID:vthorsteinsson,项目名称:Reynir,代码行数:33,代码来源:main.py

示例3: main

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import cleanup [as 别名]
def main(argv=None):
    """ Guido van Rossum's pattern for a Python main function """

    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(
                argv[1:], "hirl:u:", ["help", "init", "reparse", "limit=", "urls="]
            )
        except getopt.error as msg:
            raise Usage(msg)
        init = False
        # !!! DEBUG default limit on number of articles to parse, unless otherwise specified
        limit = 10
        reparse = False
        urls = None

        # Process options
        for o, a in opts:
            if o in ("-h", "--help"):
                print(__doc__)
                sys.exit(0)
            elif o in ("-i", "--init"):
                init = True
            elif o in ("-r", "--reparse"):
                reparse = True
            elif o in ("-l", "--limit"):
                # Maximum number of articles to parse
                try:
                    limit = int(a)
                except ValueError:
                    pass
            elif o in ("-u", "--urls"):
                urls = a  # Text file with list of URLs

        # Process arguments
        for _ in args:
            pass

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

        # Read the configuration settings file
        try:
            Settings.read("config/Reynir.conf")
            # Don't run the scraper in debug mode
            Settings.DEBUG = False
        except ConfigError as e:
            print("Configuration error: {0}".format(e), file=sys.stderr)
            return 2

        if init:
            # Initialize the scraper database
            init_roots()
        else:
            # Run the scraper
            scrape_articles(reparse=reparse, limit=limit, urls=urls)

    except Usage as err:
        print(err.msg, file=sys.stderr)
        print("For help use --help", file=sys.stderr)
        return 2

    finally:
        SessionContext.cleanup()
        Article.cleanup()

    # Completed with no error
    return 0
开发者ID:vthorsteinsson,项目名称:Reynir,代码行数:74,代码来源:scraper.py


注:本文中的article.Article.cleanup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。