From da7ec6dddaa61512b42793bb2d05152842656f98 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Fri, 31 Jan 2025 23:35:02 -0500 Subject: [PATCH] Made variable names consistent. Added MPL-2.0 text header. --- discorss.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/discorss.py b/discorss.py index 1b3df2c..288aa4e 100755 --- a/discorss.py +++ b/discorss.py @@ -3,6 +3,10 @@ # SPDX-License-Identifier: MPL-2.0 # SPDX-FileCopyrightText: © 2025 A.M. Rowsell +# 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 # webhooks. Intended to run using systemd timers. @@ -21,13 +25,17 @@ log_file_path = r"./log" log_file_name = r"/app.log" -def getDescription(feed): +def get_description(feed): try: - tempStr = str(feed.entries[0]["summary_detail"]["value"]) - desc = tempStr[:150] if len(tempStr) > 150 else tempStr + temporary_string = str(feed.entries[0]["summary_detail"]["value"]) + desc = ( + temporary_string[:150] if len(temporary_string) > 150 else temporary_string + ) except KeyError: - tempStr = str(feed.entries[0]["description"]) - desc = tempStr[:150] if len(tempStr) > 150 else tempStr + temporary_string = str(feed.entries[0]["description"]) + desc = ( + temporary_string[:150] if len(temporary_string) > 150 else temporary_string + ) return desc @@ -67,21 +75,23 @@ def main(): "fields": [ { "name": str(feed.entries[0]["title"]), - "value": getDescription(feed), + "value": get_description(feed), } ], } ], "attachments": [], } - customHeader = { - "user-agent": "DiscoRSS (https://git.frzn.dev/amr/discorss, 0.1)", + custom_header = { + "user-agent": "DiscoRSS (https://git.frzn.dev/amr/discorss, 0.2rc1)", "content-type": "application/json", } - webhookStr = json.dumps(webhook) - print(webhookStr) + webhook_string = json.dumps(webhook) + # print(webhook_string) 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 with open(config_file_path, "w") as config_file: json.dump(app_config, config_file, indent=4)