Telegram version of schneiderbot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
889 B

  1. import requests
  2. import re
  3. import html
  4. url = "https://thecodinglove.com/"
  5. def send_coding_love_gif(bot, update):
  6. random_url = re.search('href="(.*)".*\n.*random\(\)', requests.get(url).text).group(1)
  7. random_page_content = requests.get(random_url)
  8. random_page_content.encoding = 'utf-8'
  9. random_page_content = html.unescape(random_page_content.text)
  10. caption = re.search('blog-post-title">(.*)</h1>', random_page_content).group(1)
  11. gif_match = re.search('data="(.*)" type="image/gif"', random_page_content)
  12. if gif_match is None:
  13. gif_match = re.search('og:image" content="(.*)"', random_page_content)
  14. if gif_match:
  15. gif_url = gif_match.group(1)
  16. bot.send_animation(chat_id=update.message.chat_id, animation=gif_url, caption=caption)
  17. else:
  18. update.message.reply_text("Error fetching image: %s ¯\_(ツ)_/¯" % random_url)