Skip to content

Commit

Permalink
Update pypi_search.py
Browse files Browse the repository at this point in the history
Signed-off-by: Yasir Aris M <git@yasir.id>
  • Loading branch information
yasirarism authored Jan 12, 2025
1 parent 2fec8d5 commit b374614
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions misskaty/plugins/pypi_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,41 @@ async def pypi_s(_, ctx: Message):
"Please add query after command. Ex: <code>/pypi pyrogram</code>", del_in=6
)
pesan = await ctx.reply_msg("⏳ Please wait, getting data from pypi..", quote=True)
CurrentPage = 1
pypires, PageLen, btn = await getDataPypi(
pesan, kueri, CurrentPage, ctx.from_user.id
html = await fetch.get(f"https://pypi.org/pypi/{pkgname}/json")
if html.status_code != 200:
return await pesan.edit_msg("Failed connect fo pypi server")
res = html.json()
requirement = (
"".join(f"{i}, " for i in res["info"].get("requires_dist"))
if res["info"].get("requires_dist")
else "Unknown"
)
if not pypires:
return
keyboard = InlineKeyboard()
keyboard.paginate(
PageLen, CurrentPage, "page_pypi#{number}" + f"#{pesan.id}#{ctx.from_user.id}"
msg = ""
msg += f"<b>Package Name:</b> {res['info'].get('name', 'Unknown')}\n"
msg += f"<b>Version:</b> {res['info'].get('version', 'Unknown')}\n"
msg += f"<b>License:</b> {res['info'].get('license', 'Unknown')}\n"
msg += f"<b>Author:</b> {res['info'].get('author', 'Unknown')}\n"
msg += f"<b>Author Email:</b> {res['info'].get('author_email', 'Unknown')}\n"
msg += f"<b>Requirements:</b> {requirement}\n"
msg += (
f"<b>Requires Python:</b> {res['info'].get('requires_python', 'Unknown')}\n"
)
keyboard.row(InlineButton("👇 Get Info ", "Hmmm"))
keyboard.row(*btn)
msg += f"<b>HomePage:</b> {res['info'].get('home_page', 'Unknown')}\n"
msg += f"<b>Bug Track:</b> {res['info'].get('vulnerabilities', 'Unknown')}\n"
if res["info"].get("project_urls"):
msg += f"<b>Docs Url:</b> {res['info']['project_urls'].get('Documentation', 'Unknown')}\n"
msg += f"<b>Description:</b> {res['info'].get('summary', 'Unknown')}\n"
msg += (
f"<b>Pip Command:</b> pip3 install {res['info'].get('name', 'Unknown')}\n"
)
msg += f"<b>Keywords:</b> {res['info'].get('keywords', 'Unknown')}\n"
keyboard = InlineKeyboard()
keyboard.row(InlineButton("❌ Close", f"close#{ctx.from_user.id}"))
await pesan.edit_msg(pypires, reply_markup=keyboard)
try:
await pesan.edit_msg(pypires, reply_markup=keyboard)
except MessageTooLong:
url = await post_to_telegraph(False, f"{pkgname}-detail", msg)
await pesan.edit_msg(f"Result is too long:\n{url}", reply_markup=keyboard)


@app.on_callback_query(filters.create(lambda _, __, query: "page_pypi#" in query.data))
Expand Down

0 comments on commit b374614

Please sign in to comment.