Skip to content

Commit

Permalink
Do the relative math inside the lambda, in case eztv ever gets absolu…
Browse files Browse the repository at this point in the history
…te dates
  • Loading branch information
ducalex committed Aug 17, 2024
1 parent a6ec93a commit a150c65
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions nova3/engines/eztv.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def __init__(self, url):
HTMLParser.__init__(self)
self.url = url

now = datetime.now()
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: now - timedelta(hours=int(m[1]), minutes=int(m[2])),
r"(\d+)d\s+(\d+)h": lambda m: now - timedelta(days=int(m[1]), hours=int(m[2])),
r"(\d+)\s+weeks?": lambda m: now - timedelta(weeks=int(m[1])),
r"(\d+)\s+mo": lambda m: now - timedelta(weeks=int(m[1]) * 4),
r"(\d+)\s+years?": lambda m: now - timedelta(weeks=int(m[1]) * 52),
}
self.in_table_row = False
self.current_item = {}
Expand Down Expand Up @@ -68,10 +69,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).timestamp())
break

def handle_endtag(self, tag):
Expand Down

0 comments on commit a150c65

Please sign in to comment.