import re, time

class StringUtil:
    @staticmethod
    def isEmpty(x):
        if x is None:
            return True
        
        x = x.strip()
        
        if len(x)==0:
            return True
        
        return False
    
    @staticmethod
    def isTrue(x):
        if x is None:
            return False
        
        if isinstance(x, bool) and x==True:
            return True
        
        x = str(x).lower().strip()
        
        if x=="1" or x=="true" or x=="yes":
            return True
        
        return False
    
class FilterParser():
    def __init__(self, languageNames=[]):
        self.languageNames = [item.lower() for item in languageNames]

        self.tags = []
        self.normal = []
        self.special = []
        self.languages = []
        
        self.current = ""
        self.isTag = False
        self.inQuote = False
        
        self.limit = 0
        self.createdSign = ""
        self.modifiedSign = ""
        self.created = None
        self.modified = None
    
    def parseTime(self, string):
        string = string.replace("created:", "")
        string = string.replace("modified:", "")
        
        sign1 = string[0:1]
        sign2 = string[0:2]
        
        if sign2==">=" or sign2=="<=":
            date = string[2:]
            sign = sign2
        elif sign1==">" or sign1=="<" or sign1=="=":            
            date = string[1:]
            sign = sign1
        else:
            date = string[0:]
            sign = "="
        try:
            date = time.strptime(date, "%Y-%m-%d")
            created = date
            
            if sign.startswith("<"):
                created = date + 60*60*24
                
            return (sign, time.mktime(created))
        except:
            pass
        
        return None
        
    def append(self):
        if not StringUtil.isEmpty(self.current):
            if self.isTag:
                self.tags.append(self.current)
                self.current = ""
                self.isTag = False
                self.inQuote = False
            else:
                if self.current in self.languageNames:
                    self.languages.append(self.current)
                else:
                    if self.current.startswith("limit:"):
                        self.limit = int(self.current[6:])
                    elif self.current.startswith("created:"):
                        result = self.parseTime(self.current)
                        
                        if result is not None:
                            self.createdSign = result[0]
                            self.created = result[1]
                            
                    elif self.current.startswith("modified:"):
                        result = self.parseTime(self.current)
                        
                        if result is not None:
                            self.modifiedSign = result[0]
                            self.modified = result[1]
                    else:
                        self.normal.append(self.current)
                    
                self.current = ""
                self.isTag = False
                self.inQuote = False
                
    def filter(self, text):
        if StringUtil.isEmpty(text):
            return
        
        text = text.strip().lower()
        
        for char in text:
            if char=="#":
                self.isTag = True
                continue
            
            if char=="\"":
                if self.inQuote:
                    self.append()
                    self.inQuote = False
                else:
                    self.inQuote = True
                    
                continue
                    
            if char==" ":
                if self.inQuote:
                    self.current += char
                    continue
                
                self.append()
                continue
                        
            self.current += char

        self.append()

@@ -8,16 +8,26 @@
 re, time
+, datetime
 %0A%0Aclass 
@@ -1541,16 +1541,325 @@
    try:%0A
+            if date==%22today%22:%0A                now = datetime.datetime.now()%0A                date = now.strftime(%22%25Y-%25m-%25d%22)%0A            elif date==%22yesterday%22:%0A                yesterday = datetime.datetime.now() - datetime.timedelta(days=1)%0A                date = yesterday.strftime(%22%25Y-%25m-%25d%22)%0A             %0A
         

Improve filtering