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