I figured out what the issue was. Discord was trying to tell me there was a problem with the embed I was sending. The provider value was removed, and with some other tweaks it all started working. Heavy, heavy facepalm.
89 lines
2.9 KiB
Python
Executable file
89 lines
2.9 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: UTF-8 -*-
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
# SPDX-FileCopyrightText: © 2025 A.M. Rowsell <https://frzn.dev/~amr>
|
|
|
|
# DiscoRSS: A simple RSS feed reader for Discord. Takes RSS feeds and then sends them to
|
|
# webhooks. Intended to run using systemd timers.
|
|
|
|
import requests
|
|
import feedparser
|
|
from pathlib import Path
|
|
import json
|
|
import datetime
|
|
import time
|
|
import os
|
|
|
|
config_file_path = r"/etc/discorss.conf"
|
|
# config_file_path = r"discorss.conf"
|
|
# log_file_path = r"/var/log/discorss"
|
|
log_file_path = r"./log"
|
|
log_file_name = r"/app.log"
|
|
|
|
|
|
def getDescription(feed):
|
|
try:
|
|
tempStr = str(feed.entries[0]["summary_detail"]["value"])
|
|
desc = tempStr[:100] if len(tempStr) > 100 else tempStr
|
|
except KeyError:
|
|
tempStr = str(feed.entries[0]["description"])
|
|
desc = tempStr[:100] if len(tempStr) > 100 else tempStr
|
|
return desc
|
|
|
|
|
|
def main():
|
|
os.environ["TZ"] = "America/Toronto"
|
|
time.tzset()
|
|
try:
|
|
Path(log_file_path).mkdir(parents=True, exist_ok=True)
|
|
except FileExistsError:
|
|
print("This path already exists and is not a directory!")
|
|
# Load and read the config file
|
|
if not Path(config_file_path).exists():
|
|
print("No config file! Snarf. Directories were created for you.")
|
|
return
|
|
with open(config_file_path, "r") as config_file:
|
|
app_config = json.load(config_file)
|
|
now = time.mktime(time.localtime())
|
|
last_check = app_config["lastupdate"]
|
|
for hook in 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(feed.entries[0]["published"], published_time, now)
|
|
# Generate the webhook
|
|
webhook = {
|
|
"content": "RSS Feed Update from " + str(hook["name"]),
|
|
"embeds": [
|
|
{
|
|
"title": str(feed.entries[0]["title"]),
|
|
"url": str(feed.entries[0]["link"]),
|
|
"color": 5814783,
|
|
"fields": [
|
|
{
|
|
"name": str(feed.entries[0]["title"]),
|
|
"value": getDescription(feed),
|
|
}
|
|
],
|
|
}
|
|
],
|
|
"attachments": [],
|
|
}
|
|
customHeader = {
|
|
"user-agent": "DiscoRSS (https://git.frzn.dev/amr/discorss, 0.1)",
|
|
"content-type": "application/json",
|
|
}
|
|
webhookStr = json.dumps(webhook)
|
|
print(webhookStr)
|
|
if published_time > last_check and published_time < now:
|
|
r = requests.post(hook["webhook"], data=webhookStr, headers=customHeader)
|
|
app_config["lastupdate"] = now
|
|
with open(config_file_path, "w") as config_file:
|
|
json.dump(app_config, config_file, indent=4)
|
|
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|