From: khamidou Date: Fri, 19 Feb 2010 08:07:17 +0000 (+0100) Subject: added three list aliases : yesterday, today and tomorrow X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=1800156b49e1b5522393ff8677bc433bed685789;p=liszt.git added three list aliases : yesterday, today and tomorrow --- diff --git a/liszt b/liszt index 65fac61..8cc66d1 100755 --- a/liszt +++ b/liszt @@ -48,10 +48,55 @@ def create_spool_file(dict): def glob_listname(pattern): + pattern = pattern.strip() l = CachedList("lists_list") lists = l.contents + if pattern == "today": + datestr = datetime.datetime.now().strftime('%m-%d-%Y') + + if pattern not in lists: + # Add the list locally + l = CachedList(datestr) # NB: CachedList implicitly creates a list if it doesn't exists + lists.append(pattern) + l.save() + + # Create a spool file to add it remotely : + dct = {"request" : "create-list", "listname" : datestr} + create_spool_file(dct) + + return datestr + elif pattern == "yesterday": + datestr = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%m-%d-%Y') + + if pattern not in lists: + # Add the list locally + l = CachedList(datestr) # NB: CachedList implicitly creates a list if it doesn't exists + lists.append(pattern) + l.save() + + # Create a spool file to add it remotely : + dct = {"request" : "create-list", "listname" : datestr} + create_spool_file(dct) + + return datestr + elif pattern == "tomorrow": + datestr = (datetime.datetime.now() + datetime.timedelta(days=1)).strftime('%m-%d-%Y') + + if pattern not in lists: + # Add the list locally + l = CachedList(datestr) # NB: CachedList implicitly creates a list if it doesn't exists + lists.append(pattern) + l.save() + + # Create a spool file to add it remotely : + dct = {"request" : "create-list", "listname" : datestr} + create_spool_file(dct) + + return datestr + + while True: lists = fnmatch.filter(lists, pattern) if len(lists) == 0: @@ -252,20 +297,23 @@ class CommandParser(object): fields = line.split("\t") if len(fields) != 3: - # Then, only take the first field : + # Then, only take the first field and give default values to the rest: dict = {"request" : "create-entry", "listname" : listname, "index" : i, "contents" : {"title" : fields[0]}} + cdict = {"title" : fields[0], "date": datetime.datetime.now().isoformat(), "done" : 0} + else: dict = {"request" : "create-entry", "listname" : listname, "index" : i, "contents" : {"title" : fields[0], "date" : fields[1], "done": fields[2]}} + cdict = {"title" : fields[0], "date": fields[1], "done" : fields[2]} + + create_spool_file(dict) # update the cached list - - cdict = {"title" : fields[0], "date": fields[1], "done" : fields[2]} l.contents["contents"].append(cdict) - time.sleep(0.2) + l.save() os.unlink(filename)