From da7ec6dddaa61512b42793bb2d05152842656f98 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Fri, 31 Jan 2025 23:35:02 -0500 Subject: [PATCH 1/2] 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) From 243976511751ccc24a47ad6e464a28e3542e39a4 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Fri, 31 Jan 2025 23:35:31 -0500 Subject: [PATCH 2/2] Updated README with contribution guidelines. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 546db71..f8f7763 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,9 @@ WantedBy=timers.target ``` To change how often this fires, edit the OnCalendar parameter. The config above has it firing every 15 minutes at half past the minute. Look at the systemd timer man pages for help if you want to tweak it. + +## Contributing + +Want to fix something or make a suggestion? Feel free! If you want to send a pull request, you *must* run the Python `black` formatter on the source code before committing. I have this set up in my editor to automatically run every time I save the file, but you could have it run as part of a git hook or something. For non-format stuff, please just follow the code style as best you can. For Python code, I separate multi-word variable names with underscores. So it should be `feed_time`, not `feedTime` or `FeedTime` or `feed-time`. Don't ask me why, but I use camelCase for other languages... but in Python I've switched to underscores. + +If you know how and are able to, *please* sign your commits with the `-S` option to `git commit`. This shows that you are the author, especially if others have signed your keys.