本文整理汇总了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()
示例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", " "),
示例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