<commit_before>import optparse
import textwrap
import sys

from pyramid.paster import bootstrap
from pyramid.request import Request

from pushhub.worker import notify_subscribers


def process_subscriber_notices():
    description = """
    Processes subscriber notifications waiting in the queue.

    This script is meant to be run as a cron job that will regularly
    send out notices of content updates to subscriber callback URLs.

    Pass in a paster settings ini file to determine the settings
    needed.
    """
    usage = "%prog config_uri"
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description),
    )

    options, args = parser.parse_args(sys.argv[1:])
    if not len(args) >= 1:
        print("You must provide a configuration file")
        return 2
    config_uri = args[0]
    request = Request.blank('/', base_url='http://localhost/hub/')
    env = bootstrap(config_uri, request=request)
    queue = env['root'].notify_queue

    notify_subscribers(queue)

    env['closer']()


def register_listener():
    description = """
    Registers a listener URL with the hub. Useful for
    'bootstrapping' a hub with a default listener.

    Arguments:
        config_uri: the pyramid configuration to use for the hub
        listener_url: the URl to use as the listener callback
    """
    usage = "%prog config_uri listener_url"
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description),
    )

    options, args = parser.parse_args(sys.argv[1:])
    if not len(args) >= 2:
        print("You must provide a configuration file and a URL")
        return 2
    config_uri = args[0]
    listener_url = args[1]
    request = Request.blank('/', base_url='http://localhost/hub/')
    env = bootstrap(config_uri, request=request)<commit_msg>Add usage example to listemner registration script.<commit_after>import optparse
import textwrap
import sys

from pyramid.paster import bootstrap
from pyramid.request import Request

from pushhub.worker import notify_subscribers


def process_subscriber_notices():
    description = """
    Processes subscriber notifications waiting in the queue.

    This script is meant to be run as a cron job that will regularly
    send out notices of content updates to subscriber callback URLs.

    Pass in a paster settings ini file to determine the settings
    needed.
    """
    usage = "%prog config_uri"
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description),
    )

    options, args = parser.parse_args(sys.argv[1:])
    if not len(args) >= 1:
        print("You must provide a configuration file")
        return 2
    config_uri = args[0]
    request = Request.blank('/', base_url='http://localhost/hub/')
    env = bootstrap(config_uri, request=request)
    queue = env['root'].notify_queue

    notify_subscribers(queue)

    env['closer']()


def register_listener():
    description = """
    Registers a listener URL with the hub. Useful for
    'bootstrapping' a hub with a default listener.

    Arguments:
        config_uri: the pyramid configuration to use for the hub
        listener_url: the URl to use as the listener callback

    Example usage:
        bin/reg_listener etc/paster.ini#pushhub http://localhost/update_feed
    """
    usage = "%prog config_uri listener_url"
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description),
    )

    options, args = parser.parse_args(sys.argv[1:])
    if not len(args) >= 2:
        print("You must provide a configuration file and a URL")
        return 2
    config_uri = args[0]
    listener_url = args[1]
    request = Request.blank('/', base_url='http://localhost/hub/')
    env = bootstrap(config_uri, request=request)
{'fraction_non_alphanumeric': 0.08960666840323, 'fraction_numerical': 0.004688721021099245, 'mean_word_length': 3.1648590021691976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2803507', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1047, 'n_words': 354}