From fc8456da719fba5c63aed5d9b6c55d5d2af44400 Mon Sep 17 00:00:00 2001 From: Alasdair Colley Date: Thu, 5 Sep 2013 10:21:06 +0100 Subject: updated to use optparse for backwards compatibility --- wikiquery | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/wikiquery b/wikiquery index 41d8ba7..c9e4e96 100755 --- a/wikiquery +++ b/wikiquery @@ -1,6 +1,6 @@ #! /usr/bin/env python -import argparse +import optparse import sys import wikipedia @@ -18,34 +18,34 @@ def display(o): print o.encode("utf-8", "replace") def parse_args(): - parser = argparse.ArgumentParser(prog="!wiki", usage="%(prog)s [--search|--url]") + parser = optparse.OptionParser(prog="!wiki", usage="%(prog)s [--search|--url]") - parser.add_argument("topic", nargs="*") - parser.add_argument("--search", action="store_true") - parser.add_argument("--url", action="store_true") - parser.add_argument("-v", "--version", action="store_true") + parser.add_option("--search", action="store_true") + parser.add_option("--url", action="store_true") + parser.add_option("-v", "--version", action="store_true") return parser.parse_args() def main(): - args = parse_args() + options, args = parse_args() - if args.version: + if options.version: print version sys.exit(0) - if args.topic: - if args.search: - results = wikipedia.search(args.topic) + if args: + topic = args[0] + if options.search: + results = wikipedia.search(topic) if len(results) == 1: display(wikipedia.summary(results[0])) else: display(results) - elif args.url: - page = wikipedia.page(args.topic) + elif options.url: + page = wikipedia.page(topic) display(page.url) else: - display(wikipedia.summary(args.topic)) + display(wikipedia.summary(topic)) if __name__ == "__main__": main() -- cgit v1.2.3