diff options
author | Alasdair Colley <ac@dneg.com> | 2013-09-05 14:15:23 +0100 |
---|---|---|
committer | Alasdair Colley <ac@dneg.com> | 2013-09-05 14:15:23 +0100 |
commit | b6e0a1bfab082d225cf3f81fe9f4fc258c70e162 (patch) | |
tree | da0b32dc74af466cc541b0bfcfdffbf17bab60a0 | |
parent | 13b7ae43b6d073e9618ba54eaa42db922b444951 (diff) |
now supports stdin for command line arguments
-rwxr-xr-x | wikiquery | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -1,12 +1,13 @@ #! /usr/bin/env python +import shlex import optparse import sys import wikipedia from functools import partial -version = "0.0.2" +version = "0.1.0" def stringify(o): if isinstance(o, list): @@ -22,13 +23,18 @@ def display(o): print stringify(o) def parse_args(): + args = sys.argv[1:] + + if not args: + args = sys.stdin.read().splitlines() + parser = optparse.OptionParser(usage="!wiki <topic> [--search|--url]") 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() + return parser.parse_args(args) def main(): options, args = parse_args() |