You can now add feeds and check for new entries and send them to Discord
This commit is contained in:
58
discord_rss_bot/main.py
Normal file
58
discord_rss_bot/main.py
Normal file
@ -0,0 +1,58 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import typer
|
||||
from dhooks import Webhook
|
||||
from reader import FeedExistsError, make_reader
|
||||
|
||||
reader = make_reader("db.sqlite")
|
||||
|
||||
app = typer.Typer()
|
||||
hook = Webhook("")
|
||||
|
||||
|
||||
@app.command()
|
||||
def add(feed_url: str) -> None:
|
||||
"""Add a feed to the database
|
||||
|
||||
Args:
|
||||
feed_url (str): The url of the feed to add
|
||||
"""
|
||||
try:
|
||||
# Add the feed to the database
|
||||
reader.add_feed(feed_url)
|
||||
|
||||
except FeedExistsError:
|
||||
# If the feed already exists, print a message
|
||||
typer.echo(f"{feed_url} already exists")
|
||||
|
||||
# Update the feeds
|
||||
reader.update_feeds()
|
||||
|
||||
# Mark the feed as read
|
||||
entries = reader.get_entries(feed=feed_url, read=False)
|
||||
for entry in entries:
|
||||
reader.mark_entry_as_read(entry)
|
||||
|
||||
typer.echo(f"{feed_url} added")
|
||||
|
||||
|
||||
@app.command()
|
||||
def check() -> None:
|
||||
"""Check new entries for every feed"""
|
||||
# Update the feeds
|
||||
reader.update_feeds()
|
||||
|
||||
# Get new entries that are not read
|
||||
entries = reader.get_entries(read=False)
|
||||
|
||||
for entry in entries:
|
||||
# Mark the entry as read
|
||||
reader.mark_entry_as_read(entry)
|
||||
|
||||
# Send the entries to Discord
|
||||
hook.send(f":robot: :mega: {entry.title}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
1091
poetry.lock
generated
Normal file
1091
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,9 +6,16 @@ authors = ["Joakim Hellsén <tlovinator@gmail.com>"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
reader = "^2.6"
|
||||
typer = "^0.4.0"
|
||||
dhooks = "^1.1.4"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = "^5.2"
|
||||
bandit = "^1.7.1"
|
||||
flake8 = "^4.0.1"
|
||||
mypy = "^0.910"
|
||||
black = {version = "^21.12b0", allow-prereleases = true}
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
|
Reference in New Issue
Block a user