From 91eff31f183799eaf218e39be5fce077c6b95331 Mon Sep 17 00:00:00 2001 From: elpolilla Date: Mon, 26 Jan 2009 15:24:52 +0000 Subject: [PATCH] . Modified the default value of the BOT_NAME setting to the project's name . Modified spider templates to use the already-generated example item instead of a ScrapedItem --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40771 --- .../trunk/scrapy/command/commands/genspider.py | 1 + .../conf/project_template/scrapy_settings.py | 2 +- .../project_template/templates/spider_crawl.tmpl | 5 +++-- .../templates/spider_csvfeed.tmpl | 13 ++++++------- .../templates/spider_xmlfeed.tmpl | 16 ++++++---------- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/scrapy/trunk/scrapy/command/commands/genspider.py b/scrapy/trunk/scrapy/command/commands/genspider.py index f897416b7..249a4a30e 100644 --- a/scrapy/trunk/scrapy/command/commands/genspider.py +++ b/scrapy/trunk/scrapy/command/commands/genspider.py @@ -54,6 +54,7 @@ class Command(ScrapyCommand): def _genspider(self, name, site, template_file): """ Generate spider """ tvars = { + 'project_name': settings.get('BOT_NAME'), 'name': name, 'site': site, 'classname': '%sSpider' % ''.join([s.capitalize() for s in name.split('_')]) diff --git a/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py b/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py index c0e60df36..b60eddfe5 100644 --- a/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py +++ b/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py @@ -4,7 +4,7 @@ import $project_name # - Scrapy settings for $project_name - # --------------------------------------------------------------------------- -BOT_NAME = 'scrapybot' +BOT_NAME = '$project_name' BOT_VERSION = '1.0' SPIDER_MODULES = ['$project_name.spiders'] diff --git a/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl b/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl index f4a3bd2ed..a45ffdf42 100644 --- a/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl +++ b/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl @@ -2,9 +2,9 @@ import re from scrapy.xpath import HtmlXPathSelector -from scrapy.item import ScrapedItem from scrapy.link.extractors import RegexLinkExtractor from scrapy.contrib.spiders import CrawlSpider, Rule +from $project_name.items import MyItem class $classname(CrawlSpider): domain_name = '$site' @@ -15,10 +15,11 @@ class $classname(CrawlSpider): ) def parse_item(self, response): + i = MyItem() #xs = HtmlXPathSelector(response) - #i = ScrapedItem() #i.attribute('site_id', xs.x('//input[@id="sid"]/@value')) #i.attribute('name', xs.x('//div[@id="name"]')) #i.attribute('description', xs.x('//div[@id="description"]')) + return [i] SPIDER = $classname() diff --git a/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl b/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl index 12b2b7d71..bc96a3de9 100644 --- a/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl +++ b/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl @@ -1,5 +1,6 @@ # -*- coding: utf8 -*- from scrapy.contrib.spiders import CSVFeedSpider +from $project_name.items import MyItem class $classname(CSVFeedSpider): domain_name = '$site' @@ -12,12 +13,10 @@ class $classname(CSVFeedSpider): # return response def parse_row(self, response, row): - p = self.create_product(response) - #p.attribute('site_id', row['id']) - #p.attribute('supplier', self.domain_name) - #p.attribute('name', row['name']) - #p.attribute('description', row['description']) - #p.attribute('image_urls', row['image_link']) - return p + i = MyItem() + #i.attribute('url', row['url']) + #i.attribute('name', row['name']) + #i.attribute('description', row['description']) + return i SPIDER = $classname() diff --git a/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl b/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl index 87b3e10eb..7ea43375e 100644 --- a/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl +++ b/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl @@ -1,20 +1,16 @@ # -*- coding: utf8 -*- from scrapy.contrib.spiders import XMLFeedSpider +from $project_name.items import MyItem class $classname(XMLFeedSpider): domain_name = '$site' start_urls = ['http://www.$site/feed.xml'] def parse_item(self, response, xSel): - p = self.create_product(response) - #p.attribute('url', xSel('')) - #p.attribute('supplier', self.domain_name) - #p.attribute('site_id', xSel('')) - #p.attribute('name', xSel('')) - #p.attribute('description', xSel('')) - #p.attribute('image_urls', xSel('')) - #p.attribute('price', xSel('')) - #p.attribute('dimensions', xSel('')) - return p + i = MyItem() + #i.attribute('url', xSel('url')) + #i.attribute('name', xSel('name')) + #i.attribute('description', xSel('description')) + return i SPIDER = $classname()