mirror of https://github.com/scrapy/scrapy.git
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import pprint
|
|
from scrapy.command import ScrapyCommand
|
|
from scrapy.conf import settings
|
|
|
|
class Command(ScrapyCommand):
|
|
def syntax(self):
|
|
return "<domain> [domain ...]"
|
|
|
|
def short_desc(self):
|
|
return "Show all stats history stored for the given domain(s)"
|
|
|
|
def add_options(self, parser):
|
|
ScrapyCommand.add_options(self, parser)
|
|
parser.add_option("-p", "--path", dest="path", help="restrict stats to PATH", metavar="PATH")
|
|
parser.add_option("--limit", dest="limit", default='10', help="limit the number of stats")
|
|
|
|
def run(self, args, opts):
|
|
if not args:
|
|
print "A domain is required"
|
|
return
|
|
|
|
if not settings['SCRAPING_DB']:
|
|
print "SCRAPING_DB setting is required for this command"
|
|
return
|
|
|
|
from scrapy.store.db import DomainDataHistory
|
|
ddh = DomainDataHistory(settings['SCRAPING_DB'], 'domain_data_history')
|
|
|
|
for domain in args:
|
|
print "# %s" % domain
|
|
pprint.pprint(list(ddh.get(domain, path=opts.path, count=int(opts.limit))))
|
|
|