From 77acad2040152305de42ab26434edcbdae529c72 Mon Sep 17 00:00:00 2001 From: michener Date: Fri, 1 Apr 2011 23:41:14 +0000 Subject: [PATCH] Little features git-svn-id: http://photonzero.com/dotfiles/trunk@89 23f722f6-122a-0410-8cef-c75bd312dd78 --- bin/ptw | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/ptw b/bin/ptw index 2c5669d..febf252 100755 --- a/bin/ptw +++ b/bin/ptw @@ -17,8 +17,11 @@ def convertToTimedelta(toks): 'week' : timedelta(7), 'day' : timedelta(1), 'hour' : timedelta(0,0,0,0,0,1), + 'hr' : timedelta(0,0,0,0,0,1), 'minute' : timedelta(0,0,0,0,1), + 'min' : timedelta(0,0,0,0,1), 'second' : timedelta(0,1), + 'sec' : timedelta(0,1), }[unit] if toks.qty: td *= int(toks.qty) @@ -97,8 +100,8 @@ CL = CaselessLiteral today, tomorrow, yesterday, noon, midnight, now = map( CL, "today tomorrow yesterday noon midnight now".split()) plural = lambda s : Combine(CL(s) + Optional(CL("s"))) -week, day, hour, minute, second = map( plural, - "week day hour minute second".split()) +week, day, hour, hr, minute, min, second, sec = map( plural, + "week day hour hr minute min second sec".split()) am = CL("am") pm = CL("pm") COLON = Suppress(':') @@ -131,7 +134,7 @@ todayRef = (dayOffset + dayFwdBack).setParseAction(convertToTimedelta) | \ dayTimeSpec = dayRef | todayRef dayTimeSpec.setParseAction(calculateTime) -hourMinuteOrSecond = (hour | minute | second) +hourMinuteOrSecond = (hour | hr | minute | min | second | sec) timespec = Group(int4("miltime") | integer("HH") + @@ -212,12 +215,15 @@ parser.add_option("-s", "--since", dest="since", help="Number of posts to show", parser.add_option("-v", "--verbose", dest="verbose", help="Debug output", default=False, action="store_true") (options, args) = parser.parse_args() -if len(args) < 2: +if len(args) < 1: parser.print_help() exit() command = args[0] text = " ".join(args[1:]) if command == "post": + if len(text) < 1: + parser.print_help() + exit() data = {"timestamp" : time.time(), "text" : text, "client" : options.client, "hostname" : options.hostname } if not os.path.exists(os.path.expanduser("~/.ptwdb")):