Skip to content

Commit

Permalink
Add commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
hwms committed Apr 10, 2016
1 parent e77a0ab commit e03b048
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions noscrapy/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import click

from noscrapy import Queue, Scraper, Store

@click.group()
def cli():
pass

@cli.command(name='show')
def show_sitemaps():
store = Store()
for sitemap in store.get_all_sitemaps():
print(sitemap.id)

@cli.command(name='print')
@click.argument('name')
def print_sitemap(name):
store = Store()
sitemap = store.get_sitemap(name)
print(sitemap)

@cli.command(name='data')
@click.argument('name')
def data_sitemap(name):
store = Store()
for row in store.get_sitemap_data(name):
print(row)

@cli.command(name='rescrape')
@click.argument('name')
def rescrape_sitemap(name):
queue = Queue()
store = Store()
store.reset_sitemap_data_db(name)
sitemap = store.get_sitemap(name)
scraper = Scraper(queue, sitemap, store)
scraper.run()

0 comments on commit e03b048

Please sign in to comment.