feeds: centralize time format/parse

At the same code _should_ apply to most, if not all, parsers
master
pictuga 2018-11-18 16:03:02 +01:00
parent e606c5eefb
commit 9cb2d5bb86
1 changed files with 9 additions and 15 deletions

View File

@ -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])