From 0e6a035c79e2f60782bb0ad0a784a6f38ce9f77a Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sat, 17 Aug 2024 14:53:10 -0400 Subject: [PATCH] Do the relative math inside the lambda, in case eztv ever gets absolute dates --- nova3/engines/eztv.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nova3/engines/eztv.py b/nova3/engines/eztv.py index 91e935a..92e63d3 100644 --- a/nova3/engines/eztv.py +++ b/nova3/engines/eztv.py @@ -27,11 +27,11 @@ def __init__(self, url): self.url = url self.date_parsers = { - r"(\d+)h\s+(\d+)m": lambda m: timedelta(hours=int(m[1]), minutes=int(m[2])), - r"(\d+)d\s+(\d+)h": lambda m: timedelta(days=int(m[1]), hours=int(m[2])), - r"(\d+)\s+weeks?": lambda m: timedelta(weeks=int(m[1])), - r"(\d+)\s+mo": lambda m: timedelta(weeks=int(m[1]) * 4), - r"(\d+)\s+years?": lambda m: timedelta(weeks=int(m[1]) * 52), + r"(\d+)h\s+(\d+)m": lambda m, n: n - timedelta(hours=int(m[1]), minutes=int(m[2])), + r"(\d+)d\s+(\d+)h": lambda m, n: n - timedelta(days=int(m[1]), hours=int(m[2])), + r"(\d+)\s+weeks?": lambda m, n: n - timedelta(weeks=int(m[1])), + r"(\d+)\s+mo": lambda m, n: n - timedelta(weeks=int(m[1]) * 4), + r"(\d+)\s+years?": lambda m, n: n - timedelta(weeks=int(m[1]) * 52), } self.in_table_row = False self.current_item = {} @@ -68,10 +68,10 @@ def handle_data(self, data): self.current_item['seeds'] = int(data) elif self.in_table_row: # Check for a relative time - for pattern, delta in self.date_parsers.items(): + for pattern, calc in self.date_parsers.items(): m = re.match(pattern, data) if m: - self.current_item["pub_date"] = int((datetime.now() - delta(m)).timestamp()) + self.current_item["pub_date"] = int(calc(m, datetime.now()).timestamp()) break def handle_endtag(self, tag):