Soup!
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import Optional
|
||||
import asyncio
|
||||
import os
|
||||
import requests as req
|
||||
from bs4 import BeautifulSoup as soup
|
||||
|
||||
bot = commands.Bot()
|
||||
|
||||
@@ -12,7 +13,16 @@ async def search(txt):
|
||||
'request':txt
|
||||
})
|
||||
|
||||
return resp
|
||||
doc = soup(resp.text, 'html_parser')
|
||||
|
||||
if 'not found' in doc.title:
|
||||
return None
|
||||
|
||||
ref = doc.find("div", {'id': 'citation'}).get_text()
|
||||
|
||||
return {
|
||||
'ref': ref
|
||||
}
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
@@ -28,11 +38,11 @@ async def summarize(
|
||||
|
||||
resp = await search(article)
|
||||
|
||||
await interaction.followup.send(f"""Search Response:
|
||||
```
|
||||
{resp.text[:1000]}
|
||||
```
|
||||
""")
|
||||
if resp is None:
|
||||
await interaction.followup.send(f"Unable to find article: {article}")
|
||||
return
|
||||
|
||||
await interaction.followup.send(f"Article Found: \n{resp['ref']}")
|
||||
|
||||
def main():
|
||||
# TODO: Import bot token from env
|
||||
|
||||
Reference in New Issue
Block a user