pygbot - simple irc bot in python
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.
 

25 lines
748 B

import re
import requests
from bs4 import BeautifulSoup
def gettitle(bot, channel, message):
try:
link = ' '.join(message.split()[1:])
iflinkok = re.search("^http.*://", link)
if iflinkok != None:
sendyttitle(bot, channel, link, True)
else:
bot.send(channel, "Failed to get title")
except:
bot.send(channel, "Failed to get title")
def sendyttitle(bot, channel, link, sendonfailed):
try:
page = requests.get(link)
soup = BeautifulSoup(page.text, 'html.parser')
title = soup.find("meta", itemprop="name")["content"]
bot.send(channel, title)
except:
if sendonfailed == True:
bot.send(channel, "Failed to get title")