From b4187712189f542c9fe37366c2fd35acc0d5f56a Mon Sep 17 00:00:00 2001 From: Tyler Hodapp Date: Wed, 7 Feb 2018 05:09:47 +0000 Subject: [PATCH] fixed a problem with homepage by parsing lists better --- app/dragon-bot.py | 2 +- app/wallpaper.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 541be0ce..6db9043d 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -223,7 +223,7 @@ async def on_message(message): if message.content.startswith('!homepage'): await client.send_message( message.channel, - wallpaper.get_picture(message.content) + wallpaper.get_picture() ) if message.content.startswith('!docker'): diff --git a/app/wallpaper.py b/app/wallpaper.py index 072da295..9663f807 100644 --- a/app/wallpaper.py +++ b/app/wallpaper.py @@ -30,16 +30,12 @@ def get_wall(message): else: return response -def get_picture(find): - +def get_picture(): url = requests.get("http://fuckinghomepage.com") soup = BeautifulSoup(url.content) - soup.prettify(formatter=None) - for parse in soup.find_all("p"): - if 'SWEET-ASS PICTURE' in ''.join(parse.findAll(text=True)): - link = parse.find_next_sibling('p') + for pic in soup.find_all("p"): + if 'SWEET-ASS PICTURE' in ''.join(pic.findAll(text=True)): + link = pic.find_next_sibling('p') if "http://" or "https://" in link.get('href', ''): link = link.find('small').find_next('a', href=True)['href'] - return urllib.parse.unquote(link.split('http://t.umblr.com/redirect?z=')[1].split('&')[0]) - - + return urllib.parse.unquote(link.split('=')[1].split('&')[0])