Files
userbot/modules/misc/summary.py
T
forust 7fb0a0e179 chore: batch lint fixes across userbot and edu_master
- S113: Add timeout=10 to all requests calls (74 fixes)
- E722: Replace bare except: with except Exception:
- B904: Replace redundant re-raise with bare raise
- E402: Add noqa for intentional late imports after import_library()
- S102/S307/S310/S311/S603/S605/S606/S607/S108: Add noqa for intentional usage
- F601: Fix duplicate dict key in unsplash.py
- N802: Rename ReplyCheck -> reply_check with backward compat alias
- N813: Rename bs -> BS in icons.py
- B007/B020: Rename loop var _j in animations.py
- SIM102: Collapse nested if in autofwd.py
- SIM113: Use enumerate() in calculator.py
- A002: Add noqa for builtin shadowing in admlist.py
- F811: Add noqa for cohere redefinition
- edu_master: Fix ARG001, S108, S110, SIM117, apply --unsafe-fixes
- Add modules_list.txt with full module inventory
2026-06-19 15:36:25 +02:00

59 lines
1.8 KiB
Python

# copyright by https/t.me/shado_hackers
from pyrogram import Client, filters
from pyrogram.types import Message
from utils.misc import modules_help, prefix
from utils.scripts import format_exc, import_library
import_library('lxml_html_clean')
import_library('newspaper', 'newspaper3k')
nltk = import_library('nltk')
from newspaper import Article # noqa: E402
from newspaper.article import ArticleException # noqa: E402
nltk.download('all')
@Client.on_message(filters.command('summary', prefix) & filters.me)
async def summarize_article(_, message: Message):
"""
Summarize an article from a given URL.
Args:
client (Client): Pyrogram client instance.
message (Message): Incoming message.
Returns:
None
"""
# Extract the URL from the message text (removing the command part)
url = message.text.split(maxsplit=1)[1] if len(message.text.split()) > 1 else None
if not url:
await message.edit_text('Please provide a valid URL after the command.')
return
try:
# Extract and summarize the article
article = Article(url)
article.download()
article.parse()
article.nlp() # Uses NLP to analyze the article
response = f"""
<b>Article Summary</b>
<b>Title:</b> <code>{article.title}</code>
<b>Authors:</b> <code>{', '.join(article.authors) if article.authors else 'N/A'}</code>
<b>Summary:</b>
<pre>{article.summary}</pre>
"""
await message.edit_text(response)
except ArticleException:
return await message.edit_text('Unable to extract information from the provided URL.')
except Exception as e:
return await message.edit_text(f'An error occurred: {format_exc(e)}')
modules_help['summary'] = {'summary [url]': 'Reply with article links, getting summary of articles'}