summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xwikiquery28
1 files 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 <topic> [--search|--url]")
+ parser = optparse.OptionParser(prog="!wiki", usage="%(prog)s <topic> [--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()