def main(args=None):
    """
    Args:
       args (list): Command line arguments.
    Returns:
       int: exit code.
    """
    parser = get_arg_parser()
    args = parser.parse_args(args)

    query_string, cmd = get_query_string(args.query)

    search_args = {
        'query_string': query_string,
        'cmd': cmd,
        'search_engine': args.engine,
        'max_download': args.max_download
    }
    commands = None
    if not args.no_cache:
        commands = cache.get(**search_args)
    if commands is None:
        try:
            commands = search(**search_args)
        except SearchError as e:
            stderr(str(e) + u'\n')
            return 1
    cache.store(commands, **search_args)
    for cmd in commands.rank_commands(nr=args.max_hits):
        stdout(cmd.echo(verbose=args.verbose) + u'\n')
    return 0
Exemplo n.º 2
0
def main(args=None):
    """
    Args:
       args (list): Command line arguments.
    Returns:
       int: exit code.
    """
    parser = get_arg_parser()
    args = parser.parse_args(args)

    query_string, cmd = get_query_string(args.query)

    search_args = {'query_string': query_string,
                   'cmd': cmd,
                   'search_engine': args.engine,
                   'max_download': args.max_download}
    commands = None
    if not args.no_cache:
        commands = cache.get(**search_args)
    if commands is None:
        try:
            commands = search(**search_args)
        except SearchError as e:
            stderr(str(e) + u'\n')
            return 1
    cache.store(commands, **search_args)
    for cmd in commands.rank_commands(nr=args.max_hits):
        stdout(cmd.echo(verbose=args.verbose) + u'\n')
    return 0
Exemplo n.º 3
0
    def test_cache(self):
        doc = get_html_doc('search_engines', 'google.com')
        docs = list(iter_html_docs('search_engines'))
        obj = {'single': doc, 'multi': docs}

        cache.store(obj, testing=True)
        from_cache = cache.get(testing=True)

        self.assertEqual(from_cache.keys(), obj.keys())
        self.assertEqual(obj['single'].url.url, from_cache['single'].url.url)

        self.assertIsNone(cache.get(does_not_exist=True))
Exemplo n.º 4
0
    def test_cache(self):
        doc = get_html_doc('search_engines', 'google.com')
        docs = list(iter_html_docs('search_engines'))
        obj = {'single': doc, 'multi': docs}

        cache.store(obj, testing=True)
        from_cache = cache.get(testing=True)

        self.assertEqual(from_cache.keys(), obj.keys())
        self.assertEqual(obj['single'].url.url, from_cache['single'].url.url)

        self.assertIsNone(cache.get(does_not_exist=True))