Compare commits

..

2 commits

Author SHA1 Message Date
A.M. Rowsell
bd2af92ec9
First working version! Woo!
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.
2025-01-31 16:17:13 -05:00
A.M. Rowsell
e6c43876ac
Changed getDescription() to limit description string length
Now it will print at most 100 characters, though at some point
I might add something to break the string at the end of a sentence.
2025-01-31 16:16:27 -05:00

View file

@ -23,9 +23,11 @@ log_file_name = r"/app.log"
def getDescription(feed):
try:
desc = str(feed.entries[0]["summary_detail"]["value"])
tempStr = str(feed.entries[0]["summary_detail"]["value"])
desc = tempStr[:100] if len(tempStr) > 100 else tempStr
except KeyError:
desc = str(feed.entries[0]["description"])
tempStr = str(feed.entries[0]["description"])
desc = tempStr[:100] if len(tempStr) > 100 else tempStr
return desc
@ -52,29 +54,33 @@ def main():
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"]),
"description": getDescription(feed),
"provider": "DiscoRSS",
"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:
print(json.dumps(webhook))
r = requests.post(
hook["webhook"], data=json.dumps(webhook), headers=customHeader
)
print(webhook["embeds"][0]["title"])
print(r.text, r.status_code, r.json())
app_config["lastupdate"] = now
with open(config_file_path, "w") as config_file:
json.dump(app_config, config_file, indent=4)
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