#!/usr/bin/env python # # Copyright (c) 2001 Dominic Mitchell. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # """Query meerkat. usage: meerkat [-t] [-c cat] [-C chan] [-n #] [search] Submit a query to the meerkat RSS aggregator and display the results. """ __rcsid__ = "@(#) $Id: meerkat.py,v 1.1 2001/09/04 00:21:12 dom Exp $" __version__ = "$Revision: 1.1 $"[11:-2] import os,sys import getopt import xmlrpclib meerkatURI = "http://www.oreillynet.com/meerkat/xml-rpc/server.php" def usage(): print >>sys.stderr, \ "usage: %s [-t] [-c cat] [-C chan] [-n #] [search]" % sys.argv[0] sys.exit(1) def print_text(items): "Print the list of returned results in plain text." for i in items: print i['link'], ":", i['title'] print i['description'] print "" return def print_html(items): "Print the list of returned results as a HTML fragment." print "" return def meerkat(search=None, category=None, channel=None, num_items=None, text=None): "Query meerkat." srv = xmlrpclib.Server(meerkatURI) args = {} if search: args['search'] = search if category: args['category'] = category if channel: args['channel'] = channel if num_items: args['num_items'] = num_items items = srv.meerkat.getItems(args) if text: print_text(items) else: print_html(items) return if __name__ == '__main__': try: opts, args = getopt.getopt(sys.argv[1:], "c:C:n:t") except getopt.GetoptError: usage() my_args = {} if args: my_args['search'] = args[0] for o,a in opts: if o == '-n': my_args['num_items'] = a if o == '-c': my_args['category'] = a if o == '-C': my_args['channel'] = a if o == '-t': my_args['text'] = 1 apply(meerkat, (), my_args)