feeds: centralize time format/parse
At the same code _should_ apply to most, if not all, parsers
This commit is contained in:
		@@ -188,10 +188,17 @@ class ParserBase(object):
 | 
			
		||||
 | 
			
		||||
    def time_prs(self, x):
 | 
			
		||||
        # parse
 | 
			
		||||
        pass
 | 
			
		||||
        try:
 | 
			
		||||
            return parse_time(x)
 | 
			
		||||
        except ValueError:
 | 
			
		||||
            return None
 | 
			
		||||
 | 
			
		||||
    def time_fmt(self, x):
 | 
			
		||||
        # format
 | 
			
		||||
        try:
 | 
			
		||||
            time = parse_time(x)
 | 
			
		||||
            return time.strftime(self.rules['timeformat'])
 | 
			
		||||
        except ValueError:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
    def get_raw(self, rule_name):
 | 
			
		||||
@@ -351,19 +358,6 @@ class ParserXML(ParserBase):
 | 
			
		||||
    def bool_fmt(self, x):
 | 
			
		||||
        return 'true' if x else 'false'
 | 
			
		||||
 | 
			
		||||
    def time_prs(self, x):
 | 
			
		||||
        try:
 | 
			
		||||
            return parse_time(x)
 | 
			
		||||
        except ValueError:
 | 
			
		||||
            return None
 | 
			
		||||
 | 
			
		||||
    def time_fmt(self, x):
 | 
			
		||||
        try:
 | 
			
		||||
            time = parse_time(x)
 | 
			
		||||
            return time.strftime(self.rules['timeformat'])
 | 
			
		||||
        except ValueError:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
    def get_raw(self, rule_name):
 | 
			
		||||
        return self.rule_search_all(self.rules[rule_name])
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user