First attempt at hash-based feed tracking

This commit is contained in:
A.M. Rowsell 2025-02-05 15:29:04 -05:00
parent 30756fc462
commit 8683d08d1c
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9

View file

@ -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": [