]> khamidou — GitHub mirrors - liszt.git/commitdiff
added three list aliases : yesterday, today and tomorrow
authorkhamidou <khamidou@gmail.com>
Fri, 19 Feb 2010 08:07:17 +0000 (09:07 +0100)
committerkhamidou <khamidou@gmail.com>
Fri, 19 Feb 2010 08:07:17 +0000 (09:07 +0100)
liszt

diff --git a/liszt b/liszt
index 65fac61ead730f2af4c6b548231b44e938953457..8cc66d1dfa9b4d7b0b07f7e1a6f980abeab3547c 100755 (executable)
--- 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)