From eb740b5e1d03a16af14f37c8ed9f02acfeb22f43 Mon Sep 17 00:00:00 2001 From: Angerstoner Date: Fri, 12 Apr 2019 13:46:58 +0200 Subject: [PATCH] added wikihow --- misc/commandlist | 2 ++ schneiderbot.py | 5 ++++- coding_love.py => web_requests.py | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) rename coding_love.py => web_requests.py (62%) diff --git a/misc/commandlist b/misc/commandlist index 7fc9b4c..7e4e813 100644 --- a/misc/commandlist +++ b/misc/commandlist @@ -7,6 +7,8 @@ catdog - catdog pic reddit - [subreddit] random submission from reddit.com/r/[subreddit] reddit_img - [subreddit] random image submission from reddit.com/r/[subreddit] codinglove - random gif from the coding love +wikihow - random wikihow article +wiegeht - random wikihow article manta - boah ey, geile Karre! magie - Magie ist Physik durch wollen goodlife - gimme some goodlife diff --git a/schneiderbot.py b/schneiderbot.py index 6776999..d0dc6df 100755 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -7,7 +7,7 @@ import random from telegram import ParseMode from telegram.ext import Updater, CommandHandler -from coding_love import send_coding_love_gif +from web_requests import send_coding_love_gif, send_wiki_how_article from reddit import wrong_dog, hamster, reddit, reddit_img, toggle_four_twenty, four_twenty, cat, dog from schneiderbot_twitter import toggle_pepito_for_group, check_pepito_and_post_auto, check_pepito_and_post_manually from db import Db @@ -65,6 +65,7 @@ def help(bot, update): *Other fun stuff*: /codinglove - random gif from the coding love (https://thecodinglove.com) + /wikihow - random wikihow article (https://http://de.wikihow.com) /shrug - prints shrug /kill - kills you /revive - revives you @@ -199,6 +200,8 @@ def init_commands(dp): dp.add_handler(CommandHandler("simon", simon, pass_args=True)) dp.add_handler(CommandHandler("graveyard", graveyard)) dp.add_handler(CommandHandler("codinglove", send_coding_love_gif)) + dp.add_handler(CommandHandler("wiegeht", send_wiki_how_article)) + dp.add_handler(CommandHandler("wikihow", send_wiki_how_article)) dp.add_handler(CommandHandler("wrongdog", wrong_dog)) dp.add_handler(CommandHandler("hamster", hamster)) dp.add_handler(CommandHandler("reddit", reddit, pass_args=True)) diff --git a/coding_love.py b/web_requests.py similarity index 62% rename from coding_love.py rename to web_requests.py index d15a539..96d6b5a 100644 --- a/coding_love.py +++ b/web_requests.py @@ -2,11 +2,14 @@ import requests import re import html -url = "https://thecodinglove.com/" +urls = { + "codinglove": "https://thecodinglove.com/", + "wikihow": "https://de.wikihow.com/Spezial:Randomizer" +} def send_coding_love_gif(bot, update): - random_url = re.search('href="(.*)".*\n.*random\(\)', requests.get(url).text).group(1) + random_url = re.search('href="(.*)".*\n.*random\(\)', requests.get(urls["codinglove"]).text).group(1) random_page_content = requests.get(random_url) random_page_content.encoding = 'utf-8' @@ -24,3 +27,10 @@ def send_coding_love_gif(bot, update): else: update.message.reply_text("Error fetching image: %s ¯\_(ツ)_/¯" % random_url) + + +def send_wiki_how_article(bot, update): + random_howto = requests.get(urls["wikihow"]) + howto_title = re.search('(.*)', random_howto.text).group(1) + howto_url = re.search('', random_howto.text).group(1) + update.message.reply_text(howto_title + "\n" + howto_url)