forked from scrapinghub/shub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.py
More file actions
45 lines (29 loc) · 1.16 KB
/
Copy pathitems.py
File metadata and controls
45 lines (29 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import absolute_import
import click
from shub.utils import job_resource_iter, get_job
HELP = """
Given a job ID, fetch items for that job from Scrapy Cloud and output them as
JSON lines.
A job ID consists of the Scrapinghub project ID, the numerical spider ID, and
the job ID, separated by forward slashes, e.g.:
shub items 12345/2/15
You can also provide the Scrapinghub job URL instead:
shub items https://app.scrapinghub.com/p/12345/job/2/15
You can omit the project ID if you have a default target defined in your
scrapinghub.yml:
shub items 2/15
Or use any target defined in your scrapinghub.yml:
shub items production/2/15
If the job is still running, you can watch the items as they are being scraped
by providing the -f flag:
shub items -f 2/15
"""
SHORT_HELP = "Fetch items from Scrapy Cloud"
@click.command(help=HELP, short_help=SHORT_HELP)
@click.argument('job_id')
@click.option('-f', '--follow', help='output new items as they are scraped',
is_flag=True)
def cli(job_id, follow):
job = get_job(job_id)
for item in job_resource_iter(job, job.items.iter_json, follow=follow):
click.echo(item)