From 8f4c879b58ab105fa2076867dc4e9f346838e46b Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Thu, 25 Oct 2012 11:28:23 -0200 Subject: [PATCH] extended documentation on how to access crawler stats from extensions --- docs/topics/stats.rst | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/topics/stats.rst b/docs/topics/stats.rst index 2412d0e4b..d0dcc9f5e 100644 --- a/docs/topics/stats.rst +++ b/docs/topics/stats.rst @@ -29,12 +29,17 @@ opened when the spider is opened, and closed when the spider is closed. Common Stats Collector uses =========================== -Access the stats collector throught the :attr:`~scrapy.crawler.Crawler.stats` -attribute:: +Access the stats collector through the :attr:`~scrapy.crawler.Crawler.stats` +attribute. Here is an example of an extension that access stats:: - @classmethod - def from_crawler(cls, crawler): - stats = crawler.stats + class ExtensionThatAccessStats(object): + + def __init__(self, stats): + self.stats = stats + + @classmethod + def from_crawler(cls, crawler): + return cls(crawler.stats) Set stat value::