Add check for empty offer

This commit is contained in:
Dave Gallant
2024-01-16 21:29:04 -05:00
parent 8195317e29
commit 112a807102
3 changed files with 10 additions and 6 deletions

View File

@@ -17,7 +17,8 @@ class Topic:
self.title = title
self.post_time = post_time
self.web_path = web_path
self.offer = Offer(**offer)
if offer:
self.offer = Offer(**offer)
def __repr__(self):
return f"Topic({self.title})"

View File

@@ -18,12 +18,17 @@ def send_notification(
apobj = apprise.Apprise()
apobj.add(servers)
if topic.offer:
dealer_name = topic.offer.dealer_name
else:
dealer_name = ""
subject = topic.title
body = f"""\
<b>Post age:</b> {datetime.now(timezone.utc) - datetime.fromisoformat(topic.post_time)}
<br>
<br>
<b>Dealer:</b> {topic.offer.dealer_name}
<b>Dealer:</b> {dealer_name}
<br>
<br>
<b>Deal:</b> {topic.title}

View File

@@ -65,7 +65,7 @@ def look_for_matches(
topic_title = topic.title.lower()
dealer_name = ""
if topic.offer.dealer_name is not None:
if topic.offer and topic.offer.dealer_name is not None:
dealer_name = topic.offer.dealer_name.lower()
if re.search(expression, topic_title):
found_match = True
@@ -86,7 +86,5 @@ def look_for_matches(
previous_matches[str(topic.topic_id)] = 1
send_notification(topic, posts, expression, apprise_url)
else:
logger.debug(
f"Already matched topic '{topic.offer.dealer_name} - {topic.title}'"
)
logger.debug(f"Already matched topic '{topic.title}'")
break