diff --git a/news/__pycache__/pool.cpython-312.pyc b/news/__pycache__/pool.cpython-312.pyc index 497e113..774bfad 100644 Binary files a/news/__pycache__/pool.cpython-312.pyc and b/news/__pycache__/pool.cpython-312.pyc differ diff --git a/news/main.py b/news/main.py index b190248..8740e1d 100644 --- a/news/main.py +++ b/news/main.py @@ -196,6 +196,13 @@ async def handle_article_url(message: discord.Message, url: str) -> None: try: title, processed_html = await article_repository.get_article(url) + if await article_repository.has_paragraphs(url): + await message.channel.send("This article has already been processed.") + LOGGER.info(f"Article {url} already processed") + return + + LOGGER.info(f"Article {url} has not been processed. Beginning now!") + summary_bot = ChatBot(summary_system_prompt) summary_parts = await summary_bot.multi_summary(processed_html, options={ diff --git a/news/pool.py b/news/pool.py index 709b3e1..cd6e93b 100644 --- a/news/pool.py +++ b/news/pool.py @@ -176,6 +176,20 @@ class ArticleRepository: return title, processed_html + async def has_paragraphs(self, url) -> bool: + async with self._lock: + row = self._row_for_url(url) + if not row: + return False + + cur = self._conn.cursor() + row = cur.execute(f"SELECT COUNT(*) FROM summaries WHERE article_id = {row[0]}") + + result = row.fetchone() + if not row.fetchone() or row.fetchone()[0] == 0: + return False + return True + async def set_paragraphs(self, url, paragraphs, summary, summary_ratings, topics, topic_ratings): async with self._lock: article_id = self._row_for_url(url)[0]