import feedparser import time import requests import secret_loader SESSION = requests.Session() secrets = secret_loader.SecretLoader() WEBHOOK_URL = secrets.load_or_fail('WEBHOOK_URL') FEED_URL = secrets.load_or_fail('FEED_URL') def send_feed_notice(text: str): app_message = {'text': text} message_headers = {'Content-Type': 'application/json; charset=UTF-8'} response = requests.post( WEBHOOK_URL, headers=message_headers, json=app_message, ) def get_feed(): response = SESSION.get(FEED_URL) return feedparser.parse(response.text) def get_seen_entry_ids() -> set[str]: with open('output/entries_db.txt') as f: return f.read().split('\n') def mark_as_sent(entry_id: str): with open('output/entries_db.txt', 'a') as f: f.write(entry_id) f.write('\n') def check_for_new_updates(): seen_entries = get_seen_entry_ids() feed = get_feed() for entry in reversed(feed.entries): if entry.id in seen_entries: continue msg = f'Feed <{feed.feed.link}|{feed.feed.title}> updated: <{entry.link}|{entry.title}>' send_feed_notice(msg) mark_as_sent(entry.id) def main(): while True: check_for_new_updates() time.sleep(600) if __name__ == '__main__': main()