From 61bc14154bddba997499cf86e3aee1b16f0b0e45 Mon Sep 17 00:00:00 2001 From: Zoid Date: Tue, 19 Sep 2017 17:08:51 -0600 Subject: [PATCH] Add support for fuckinghomepage.com. Fixes #23 --- .gitlab-ci.yml | 4 ++-- Dockerfile | 4 ++-- Dockerfile-test-env | 2 +- app/dragon-bot.py | 5 +++++ app/wallpaper.py | 19 ++++++++++++++++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7bb5601..515a5fe7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ services: before_script: - apk add --no-cache python3 - - pip3 install pylint requests discord.py docker pylint wolframalpha + - pip3 install pylint requests discord.py docker pylint wolframalpha beautifulsoup4 stages: - test @@ -28,4 +28,4 @@ build_and_push_container: only: - master tags: - - docker \ No newline at end of file + - docker diff --git a/Dockerfile b/Dockerfile index f3aeb963..708a215b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6 LABEL name="Dragon Bot" RUN apk update && apk add --no-cache docker -RUN pip install requests discord.py docker wolframalpha +RUN pip install requests discord.py docker wolframalpha beautifulsoup4 ADD app /app -CMD python app/dragon-bot.py \ No newline at end of file +CMD python app/dragon-bot.py diff --git a/Dockerfile-test-env b/Dockerfile-test-env index 0f629ee9..bfab36c8 100644 --- a/Dockerfile-test-env +++ b/Dockerfile-test-env @@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6 LABEL name="Dragon Bot Test environment" RUN apk update && apk add --no-cache vim docker -RUN pip install requests discord.py docker pylint wolframalpha +RUN pip install requests discord.py docker pylint wolframalpha beautifulsoup4 ADD app /app RUN printf "\n\nTesting your python code for errors\n\n" && \ diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 8a6ec695..6a8aaae3 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -147,7 +147,12 @@ async def on_message(message): message.channel, wallpaper.get_wall(message.content) ) + if message.content.startswith('!homepage'): + await client.send_message( + message.channel, + wallpaper.get_picture(message.content) + ) if message.content.startswith('!docker'): # Check permissions if not role_check.docker_permissions(message.author.roles): diff --git a/app/wallpaper.py b/app/wallpaper.py index 6cf89456..072da295 100644 --- a/app/wallpaper.py +++ b/app/wallpaper.py @@ -1,5 +1,8 @@ import requests - +import requests +from bs4 import BeautifulSoup +import urllib +from urllib.parse import urlparse def get_wall(message): unsplash_url = "https://source.unsplash.com/3840x2160/?" @@ -26,3 +29,17 @@ def get_wall(message): return "Could not find an image for those tags." else: return response + +def get_picture(find): + + 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') + 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]) + +