Made variable names consistent. Added MPL-2.0 text header.

This commit is contained in:
A.M. Rowsell 2025-01-31 23:35:02 -05:00
parent 40156c434f
commit da7ec6ddda
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9

View file

@ -3,6 +3,10 @@
# SPDX-License-Identifier: MPL-2.0 # SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: © 2025 A.M. Rowsell <https://frzn.dev/~amr> # SPDX-FileCopyrightText: © 2025 A.M. Rowsell <https://frzn.dev/~amr>
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# DiscoRSS: A simple RSS feed reader for Discord. Takes RSS feeds and then sends them to # DiscoRSS: A simple RSS feed reader for Discord. Takes RSS feeds and then sends them to
# webhooks. Intended to run using systemd timers. # webhooks. Intended to run using systemd timers.
@ -21,13 +25,17 @@ log_file_path = r"./log"
log_file_name = r"/app.log" log_file_name = r"/app.log"
def getDescription(feed): def get_description(feed):
try: try:
tempStr = str(feed.entries[0]["summary_detail"]["value"]) temporary_string = str(feed.entries[0]["summary_detail"]["value"])
desc = tempStr[:150] if len(tempStr) > 150 else tempStr desc = (
temporary_string[:150] if len(temporary_string) > 150 else temporary_string
)
except KeyError: except KeyError:
tempStr = str(feed.entries[0]["description"]) temporary_string = str(feed.entries[0]["description"])
desc = tempStr[:150] if len(tempStr) > 150 else tempStr desc = (
temporary_string[:150] if len(temporary_string) > 150 else temporary_string
)
return desc return desc
@ -67,21 +75,23 @@ def main():
"fields": [ "fields": [
{ {
"name": str(feed.entries[0]["title"]), "name": str(feed.entries[0]["title"]),
"value": getDescription(feed), "value": get_description(feed),
} }
], ],
} }
], ],
"attachments": [], "attachments": [],
} }
customHeader = { custom_header = {
"user-agent": "DiscoRSS (https://git.frzn.dev/amr/discorss, 0.1)", "user-agent": "DiscoRSS (https://git.frzn.dev/amr/discorss, 0.2rc1)",
"content-type": "application/json", "content-type": "application/json",
} }
webhookStr = json.dumps(webhook) webhook_string = json.dumps(webhook)
print(webhookStr) # print(webhook_string)
if published_time > last_check and published_time < now: if published_time > last_check and published_time < now:
r = requests.post(hook["webhook"], data=webhookStr, headers=customHeader) r = requests.post(
hook["webhook"], data=webhook_string, headers=custom_header
)
app_config["lastupdate"] = now app_config["lastupdate"] = now
with open(config_file_path, "w") as config_file: with open(config_file_path, "w") as config_file:
json.dump(app_config, config_file, indent=4) json.dump(app_config, config_file, indent=4)