-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize latestreleasedate pipeline to pluck any data from each pub…
…lisher - Refactor Pluck (LatestReleaeData) item pipeline to be more generic - Log the spiders that will be run by the pluck (latestreleasedate) command - Add `package_pointer`, `release_pointer`, `truncate` and remove `latest` spider arguments - Add `skip_pluck` (skip_latest_release_date) to georgia_records, mexico_nuevo_leon_records - Rename classes, variables, settings and filenames accordingly - Fix line lengths
- Loading branch information
1 parent
f010dfb
commit 864a15c
Showing
23 changed files
with
279 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import json | ||
import logging | ||
import os | ||
from collections import defaultdict | ||
from datetime import datetime | ||
|
||
from scrapy.commands import ScrapyCommand | ||
from scrapy.crawler import CrawlerProcess | ||
from scrapy.exceptions import UsageError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Pluck(ScrapyCommand): | ||
def short_desc(self): | ||
return 'Pluck one data value per publisher' | ||
|
||
def add_options(self, parser): | ||
ScrapyCommand.add_options(self, parser) | ||
parser.add_option('-p', '--package-pointer', help='The JSON Pointer to the value in the package') | ||
parser.add_option('-r', '--release-pointer', help='The JSON Pointer to the value in the release') | ||
parser.add_option('-t', '--truncate', type=int, help='Truncate the value to this number of characters') | ||
|
||
def run(self, args, opts): | ||
if not (opts.package_pointer ^ opts.release_pointer): | ||
raise UsageError('Exactly one of --package-pointer or --release-pointer must be set.') | ||
|
||
# Stop after one item or error. | ||
self.settings.set('CLOSESPIDER_ITEMCOUNT', 1) | ||
self.settings.set('CLOSESPIDER_ERRORCOUNT', 1) | ||
# Disable LogStats extension. | ||
self.settings.set('LOGSTATS_INTERVAL', None) | ||
# Limit concurrent requests, to download the minimum. | ||
self.settings.set('CONCURRENT_REQUESTS', 1) | ||
|
||
if os.path.isfile('pluck.csv'): | ||
os.unlink('pluck.csv') | ||
|
||
runner = CrawlerProcess(settings=self.settings) | ||
|
||
year = datetime.today().year | ||
skipped = defaultdict(list) | ||
running = [] | ||
for spider_name in runner.spider_loader.list(): | ||
if spider_name != 'test_fail': | ||
spidercls = runner.spider_loader.load(spider_name) | ||
if hasattr(spidercls, 'skip_pluck'): | ||
skipped[spidercls.skip_pluck].append(spider_name) | ||
else: | ||
running.append(spider_name) | ||
runner.crawl(spidercls, year=year, package_pointer=opts.package_pointer, | ||
release_pointer=opts.release_pointer, truncate=opts.truncate) | ||
|
||
with open('pluck_skipped.json', 'w') as f: | ||
json.dump(skipped, f, indent=2) | ||
|
||
logger.info(f"Running {len(running)} spiders: {', '.join(sorted(running))}") | ||
runner.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.