From 9cb2d5bb86a31d5b6fde623125821e31109fbb3b Mon Sep 17 00:00:00 2001 From: pictuga Date: Sun, 18 Nov 2018 16:03:02 +0100 Subject: [PATCH] feeds: centralize time format/parse At the same code _should_ apply to most, if not all, parsers --- morss/feeds.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/morss/feeds.py b/morss/feeds.py index 924b588..50976f8 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -188,11 +188,18 @@ 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 - pass + try: + time = parse_time(x) + return time.strftime(self.rules['timeformat']) + except ValueError: + pass def get_raw(self, rule_name): # get the raw output, for self.get_raw('items') @@ -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])