Close database connection when command is finished instead of waiting for GC
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from contextlib import closing
|
||||
|
||||
import typer
|
||||
from dhooks import Webhook
|
||||
@ -6,9 +6,8 @@ from reader import FeedExistsError, make_reader
|
||||
|
||||
from discord_rss_bot.settings import Settings
|
||||
|
||||
app = typer.Typer() # For CLI (https://typer.tiangolo.com/)
|
||||
hook = Webhook(Settings.webhook_url) # For Webhooks (https://github.com/kyb3r/dhooks)
|
||||
reader = make_reader(Settings.db_file) # For RSS (https://github.com/lemon24/reader)
|
||||
app = typer.Typer()
|
||||
hook = Webhook(Settings.webhook_url)
|
||||
|
||||
|
||||
@app.command()
|
||||
@ -20,7 +19,9 @@ def add(
|
||||
|
||||
Args:
|
||||
feed_url (str): The url of the feed to add
|
||||
notify_discord (bool): Whether to send a message to Discord when the feed is added
|
||||
"""
|
||||
with closing(make_reader(Settings.db_file)) as reader:
|
||||
try:
|
||||
# Add the feed to the database
|
||||
reader.add_feed(feed_url)
|
||||
@ -51,6 +52,7 @@ def add(
|
||||
@app.command()
|
||||
def check() -> None:
|
||||
"""Check new entries for every feed"""
|
||||
with closing(make_reader(Settings.db_file)) as reader:
|
||||
feed_count = reader.get_feed_counts()
|
||||
entry_count = reader.get_entry_counts()
|
||||
|
||||
|
Reference in New Issue
Block a user