First attempt at hash-based feed tracking
This commit is contained in:
parent
30756fc462
commit
8683d08d1c
1 changed files with 10 additions and 1 deletions
11
discorss.py
11
discorss.py
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import feedparser
|
import feedparser
|
||||||
|
import hashlib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
@ -59,12 +60,20 @@ def main():
|
||||||
app_config = json.load(config_file)
|
app_config = json.load(config_file)
|
||||||
now = time.mktime(time.localtime())
|
now = time.mktime(time.localtime())
|
||||||
last_check = app_config["lastupdate"]
|
last_check = app_config["lastupdate"]
|
||||||
for hook in app_config["feeds"]:
|
for i, hook in enumerate(app_config["feeds"]):
|
||||||
# Get the feed
|
# Get the feed
|
||||||
feed = feedparser.parse(hook["url"])
|
feed = feedparser.parse(hook["url"])
|
||||||
published_time = time.mktime(feed.entries[0]["published_parsed"])
|
published_time = time.mktime(feed.entries[0]["published_parsed"])
|
||||||
published_time = published_time + hook["offset"]
|
published_time = published_time + hook["offset"]
|
||||||
print("Parsing feed {}...".format(hook["name"]))
|
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
|
# Generate the webhook
|
||||||
webhook = {
|
webhook = {
|
||||||
"embeds": [
|
"embeds": [
|
||||||
|
|
Loading…
Add table
Reference in a new issue