1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-26 18:23:57 +00:00

add options -o and -t to the runspider command

copy the codes from commands/crawl.py to commands/runspider.py
This commit is contained in:
Jae-Myoung Yu 2012-09-25 09:38:00 +09:00
parent a6eacf2c9b
commit e94bd8187c

View File

@ -38,6 +38,10 @@ class Command(ScrapyCommand):
ScrapyCommand.add_options(self, parser)
parser.add_option("-a", dest="spargs", action="append", default=[], metavar="NAME=VALUE", \
help="set spider argument (may be repeated)")
parser.add_option("-o", "--output", metavar="FILE", \
help="dump scraped items into FILE (use - for stdout)")
parser.add_option("-t", "--output-format", metavar="FORMAT", default="jsonlines", \
help="format to use for dumping items with -o (default: %default)")
def process_options(self, args, opts):
ScrapyCommand.process_options(self, args, opts)
@ -45,6 +49,12 @@ class Command(ScrapyCommand):
opts.spargs = arglist_to_dict(opts.spargs)
except ValueError:
raise UsageError("Invalid -a value, use -a NAME=VALUE", print_help=False)
if opts.output:
if opts.output == '-':
self.settings.overrides['FEED_URI'] = 'stdout:'
else:
self.settings.overrides['FEED_URI'] = opts.output
self.settings.overrides['FEED_FORMAT'] = opts.output_format
def run(self, args, opts):
if len(args) != 1: