From 8683d08d1c6006be6503205991c73fb27e4dd179 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Wed, 5 Feb 2025 15:29:04 -0500 Subject: [PATCH] First attempt at hash-based feed tracking --- discorss.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/discorss.py b/discorss.py index 46224b3..bd1f182 100755 --- a/discorss.py +++ b/discorss.py @@ -12,6 +12,7 @@ import requests import feedparser +import hashlib from pathlib import Path import json import time @@ -59,12 +60,20 @@ def main(): app_config = json.load(config_file) now = time.mktime(time.localtime()) last_check = app_config["lastupdate"] - for hook in app_config["feeds"]: + for i, hook in enumerate(app_config["feeds"]): # Get the feed feed = feedparser.parse(hook["url"]) published_time = time.mktime(feed.entries[0]["published_parsed"]) published_time = published_time + hook["offset"] print("Parsing feed {}...".format(hook["name"])) + new_hash = hashlib.sha3_512(feed.entries[0]["title"]) + try: + if hook["lasthash"] != new_hash: + app_config["feeds"][i]["lasthash"] = new_hash + else: + continue + except KeyError: + app_config["feeds"][i]["lasthash"] = new_hash # Generate the webhook webhook = { "embeds": [