Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new cli option to insert url into existing crawl. #290

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions brozzler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,50 @@ def brozzler_new_site(argv=None):
brozzler.new_site(frontier, site)


def brozzler_new_page(argv=None):
"""
Command line utility entry point for queuing a new brozzler page.
Takes a url, site_id, and parent_page_id, and adds a page object in rethinkdb, which
brozzler-workers will look at and start crawling.
"""
argv = argv or sys.argv
arg_parser = argparse.ArgumentParser(
prog=os.path.basename(argv[0]),
description="brozzler-new-page - queue url to brozzler site",
formatter_class=BetterArgumentDefaultsHelpFormatter,
)
arg_parser.add_argument("url", metavar="URL", help="URL to add to site")
arg_parser.add_argument(
"site_id", metavar="SITE_ID", help="UUID of site object to add the page to"
)
arg_parser.add_argument(
"parent_page_id",
metavar="PARENT_PAGE_ID",
help="ID of Page object to add the page as an outlink to",
)
add_rethinkdb_options(arg_parser)
add_common_options(arg_parser, argv)
args = arg_parser.parse_args(args=argv[1:])
configure_logging(args)

rr = rethinker(args)

site_result = rr.table("sites").get(args.site_id).run()
if not site_result:
raise Exception()
site = brozzler.Site(rr, site_result)

parent_page_result = rr.table("pages").get(args.parent_page_id).run()
if not parent_page_result:
raise Exception()
parent_page = brozzler.Page(rr, parent_page_result)

frontier = brozzler.RethinkDbFrontier(rr)
frontier.scope_and_schedule_outlinks(
site=site, parent_page=parent_page, outlinks=[args.url]
)


def brozzler_worker(argv=None):
"""
Main entry point for brozzler, gets sites and pages to brozzle from
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def find_package_data(package):

setuptools.setup(
name="brozzler",
version="1.5.54",
version="1.5.55",
description="Distributed web crawling with browsers",
url="https://github.com/internetarchive/brozzler",
author="Noah Levitt",
Expand All @@ -51,6 +51,7 @@ def find_package_data(package):
"brozzle-page=brozzler.cli:brozzle_page",
"brozzler-new-job=brozzler.cli:brozzler_new_job",
"brozzler-new-site=brozzler.cli:brozzler_new_site",
"brozzler-new-page=brozzler.cli:brozzler_new_page",
"brozzler-worker=brozzler.cli:brozzler_worker",
"brozzler-ensure-tables=brozzler.cli:brozzler_ensure_tables",
"brozzler-list-captures=brozzler.cli:brozzler_list_captures",
Expand Down