Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions limbo/plugins/imgur_url_titles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""posts titles of imagur images if exist when a link is posted"""
import re
import requests
from bs4 import BeautifulSoup


regex = re.compile("\\.imgur\\.com/(.+)\\..+", re.IGNORECASE)

generic_imgur_title = "Imgur: The most awesome images on the Internet".lower()


def get_image_title(url):
soup = BeautifulSoup(requests.get(url).text, "html5lib")
return soup.title.text.strip()


def on_message(msg, server):
text = msg.get("text", "")
match = regex.findall(text)
if not match or len(match) < 1:
return
image_title = get_image_title("https://imgur.com/{}".format(match[0]))
if not isGenericTitle(image_title):
return image_title


def isGenericTitle(title):
"""
:type title: str
"""
if title.lower() == generic_imgur_title:
return True
else:
return False