Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
ce71ef1e81 | |||
b72f1d7291 | |||
457e2c3315 |
3 changed files with 11 additions and 26 deletions
10
Dockerfile
10
Dockerfile
|
@ -1,10 +0,0 @@
|
||||||
FROM python:3.13.2-alpine3.21
|
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
|
||||||
|
|
||||||
COPY discorss.py ./
|
|
||||||
COPY discorss.conf /etc/
|
|
||||||
|
|
||||||
RUN pip install --no-cache-dir requests feedparser
|
|
||||||
|
|
||||||
CMD [ "python", "discorss.py" ]
|
|
|
@ -23,7 +23,7 @@ Logging was recently enabled. Make sure that the user running the script (especi
|
||||||
|
|
||||||
To configure the script, create ~/.config/discorss/discorss.conf with the following structure:
|
To configure the script, create ~/.config/discorss/discorss.conf with the following structure:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"feeds": [
|
"feeds": [
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ To automate feed posting, create a systemd service and timer to execute the scri
|
||||||
|
|
||||||
Use the command `systemctl --user edit --full --force discorss.service` and then paste in something like this:
|
Use the command `systemctl --user edit --full --force discorss.service` and then paste in something like this:
|
||||||
|
|
||||||
```
|
```systemd
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Discord RSS feeder
|
Description=Discord RSS feeder
|
||||||
Wants=discorss.timer
|
Wants=discorss.timer
|
||||||
|
@ -68,7 +68,7 @@ WantedBy=default.target
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure to edit the ExecStart to point to the correct location. Then we need a systemd timer to automatically fire the script. Run `systemctl --user edit --full --force discorss.timer` and then paste in this:
|
Make sure to edit the ExecStart to point to the correct location. Then we need a systemd timer to automatically fire the script. Run `systemctl --user edit --full --force discorss.timer` and then paste in this:
|
||||||
```
|
```systemd
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Timer for DiscoRSS
|
Description=Timer for DiscoRSS
|
||||||
Requires=discorss.service
|
Requires=discorss.service
|
||||||
|
|
21
discorss.py
21
discorss.py
|
@ -53,7 +53,6 @@ def get_description(feed, length=250, min_length=150, addons=None):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
length -= 1
|
length -= 1
|
||||||
desc = temporary_string[:length]
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
temporary_string = str(feed["description"])
|
temporary_string = str(feed["description"])
|
||||||
temporary_string = html_filter.sub("", temporary_string)
|
temporary_string = html_filter.sub("", temporary_string)
|
||||||
|
@ -62,7 +61,10 @@ def get_description(feed, length=250, min_length=150, addons=None):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
length -= 1
|
length -= 1
|
||||||
desc = temporary_string[:length]
|
|
||||||
|
desc = temporary_string[:length]
|
||||||
|
if addons is not None:
|
||||||
|
desc = desc + str(addons)
|
||||||
return desc
|
return desc
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ def setupPaths():
|
||||||
Path(config_dir).mkdir(parents=True, exist_ok=True)
|
Path(config_dir).mkdir(parents=True, exist_ok=True)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
print(
|
print(
|
||||||
"The config dir {} already exists and is not a directory! Please fix manually.".format(
|
"The config dir {} already exists and is not a directory! Please fix manually. Quitting!".format(
|
||||||
config_dir
|
config_dir
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -136,11 +138,12 @@ def main():
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if bad_time is True:
|
if bad_time is True:
|
||||||
logger.warning(
|
logger.debug(
|
||||||
"Feed %s doesn't supply a published time, using updated time instead",
|
"Feed %s doesn't supply a published time, using updated time instead",
|
||||||
hook["name"],
|
hook["name"],
|
||||||
)
|
)
|
||||||
# Hash the title and time of the latest post and use that to determine if it's been posted
|
# Hash the title and time of the latest post and use that to determine if it's been posted
|
||||||
|
# Yes, SHA3-512 is totally unnecessary for this purpose, but I love SHA3
|
||||||
new_hash = hashlib.sha3_512(
|
new_hash = hashlib.sha3_512(
|
||||||
bytes(latest_post["title"] + str(published_time), "utf-8")
|
bytes(latest_post["title"] + str(published_time), "utf-8")
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
|
@ -210,12 +213,4 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if os.environ["INVOCATION_ID"]:
|
main()
|
||||||
main()
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
main()
|
|
||||||
time.sleep(15 * 60)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
exit(0)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue