From 0501fdbe9049ba07f233059524c823a0865b0761 Mon Sep 17 00:00:00 2001 From: Alasdair Date: Thu, 5 Sep 2013 15:14:57 +0200 Subject: now supports stdin for arguments --- wikiquery | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wikiquery b/wikiquery index 10356dd..7d1ed5f 100755 --- a/wikiquery +++ b/wikiquery @@ -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 [--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() -- cgit v1.2.3