27 lines
904 B
Python
27 lines
904 B
Python
import requests
|
|
from app_log import LoggingManager
|
|
|
|
|
|
class WebhookNotifier:
|
|
def __init__(self, webhook_url, disable_webhook=False):
|
|
self.webhook_url = webhook_url
|
|
self.disable_webhook = disable_webhook
|
|
self.log_manager = LoggingManager("scraper.log")
|
|
|
|
def send_notification(self, post):
|
|
title = post.title
|
|
url = post.url
|
|
permalink = post.permalink
|
|
selftext = post.selftext
|
|
content = f"""
|
|
**New Deal!**
|
|
**Title:** {title}
|
|
**URL:** {url}
|
|
**Permalink:** https://old.reddit.com{permalink}
|
|
**Selftext:** {selftext}"""
|
|
if not self.disable_webhook:
|
|
self.log_manager.log(f"Sending notification to {self.webhook_url}")
|
|
try:
|
|
requests.post(self.webhook_url, data={"content": content})
|
|
except Exception as e:
|
|
self.log_manager.error(f"Failed to send notification: {e}") |