From b4253d58f1a664f17accceaa179e0a272e81e9f9 Mon Sep 17 00:00:00 2001 From: "DavidCrompton1192@gmail.com" Date: Fri, 17 Mar 2023 22:19:04 -0400 Subject: [PATCH] Get PDF --- handyhelper/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/handyhelper/__init__.py b/handyhelper/__init__.py index 3156644..065fd21 100644 --- a/handyhelper/__init__.py +++ b/handyhelper/__init__.py @@ -9,7 +9,8 @@ from bs4 import BeautifulSoup as soup bot = commands.Bot() async def search(txt): - resp = req.post("https://www.sci-hub.st/", data={ + url = "https://www.sci-hub.st/" + resp = req.post(url, data={ 'request':txt }) @@ -18,10 +19,12 @@ async def search(txt): if 'not found' in doc.title: return None - ref = doc.find("div", {'id': 'citation'}).get_text() + ref = doc.find('div', {'id': 'citation'}).get_text() + pdf = doc.find('div', {'id': 'pdf'})['src'] return { - 'ref': ref + 'ref': ref, + 'pdf': f"{url}/{pdf}" } @bot.event @@ -42,7 +45,8 @@ async def summarize( await interaction.followup.send(f"Unable to find article: {article}") return - await interaction.followup.send(f"Article Found: \n{resp['ref']}") + await interaction.followup.send(f"""Article Found: \n{resp['ref']} + PDF loc: {resp['pdf']}""") def main(): # TODO: Import bot token from env