Merge pull request #129 from bobloy/lovecalculator_develop
Lovecalculator Fixes and Improvements
This commit is contained in:
commit
037e091207
@ -1,9 +1,13 @@
|
||||
import logging
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
from bs4 import BeautifulSoup
|
||||
from redbot.core import commands
|
||||
from redbot.core.commands import Cog
|
||||
|
||||
log = logging.getLogger("red.fox_v3.chatter")
|
||||
|
||||
|
||||
class LoveCalculator(Cog):
|
||||
"""Calculate the love percentage for two users!"""
|
||||
@ -28,17 +32,25 @@ class LoveCalculator(Cog):
|
||||
url = "https://www.lovecalculator.com/love.php?name1={}&name2={}".format(
|
||||
x.replace(" ", "+"), y.replace(" ", "+")
|
||||
)
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with aiohttp.ClientSession(headers={"Connection": "keep-alive"}) as session:
|
||||
async with session.get(url) as response:
|
||||
soup_object = BeautifulSoup(await response.text(), "html.parser")
|
||||
try:
|
||||
description = (
|
||||
soup_object.find("div", attrs={"class": "result__score"})
|
||||
.get_text()
|
||||
.strip()
|
||||
)
|
||||
except:
|
||||
description = "Dr. Love is busy right now"
|
||||
assert response.status == 200
|
||||
resp = await response.text()
|
||||
|
||||
log.debug(f"{resp=}")
|
||||
soup_object = BeautifulSoup(resp, "html.parser")
|
||||
|
||||
description = soup_object.find("div", class_="result__score").get_text()
|
||||
|
||||
if description is None:
|
||||
description = "Dr. Love is busy right now"
|
||||
else:
|
||||
description = description.strip()
|
||||
|
||||
result_image = soup_object.find("img", class_="result__image").get("src")
|
||||
|
||||
result_text = soup_object.find("div", class_="result-text").get_text()
|
||||
result_text = " ".join(result_text.split())
|
||||
|
||||
try:
|
||||
z = description[:2]
|
||||
@ -47,11 +59,15 @@ class LoveCalculator(Cog):
|
||||
emoji = "❤"
|
||||
else:
|
||||
emoji = "💔"
|
||||
title = "Dr. Love says that the love percentage for {} and {} is:".format(x, y)
|
||||
title = f"Dr. Love says that the love percentage for {x} and {y} is: {emoji} {description} {emoji}"
|
||||
except:
|
||||
emoji = ""
|
||||
title = "Dr. Love has left a note for you."
|
||||
|
||||
description = emoji + " " + description + " " + emoji
|
||||
em = discord.Embed(title=title, description=description, color=discord.Color.red())
|
||||
em = discord.Embed(
|
||||
title=title,
|
||||
description=result_text,
|
||||
color=discord.Color.red(),
|
||||
url=f"https://www.lovecalculator.com/{result_image}",
|
||||
)
|
||||
|
||||
await ctx.send(embed=em)
|
||||
|
Loading…
x
Reference in New Issue
Block a user