Compare commits
2 commits
40156c434f
...
2439765117
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2439765117 |
||
|
|
da7ec6ddda |
2 changed files with 27 additions and 11 deletions
|
|
@ -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.
|
||||
|
|
|
|||
32
discorss.py
32
discorss.py
|
|
@ -3,6 +3,10 @@
|
|||
# SPDX-License-Identifier: MPL-2.0
|
||||
# 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
|
||||
# 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue