def print_title(url, chan, nick, mode, cont):
    try:
        r = requests.get(url, verify=False)
        if r.headers["content-type"].split("/")[0] == "text":
            html_doc = r.text
            r.close()
            title = snarfer(html_doc)
            title = HTMLParser().unescape(title)
            title = title.lstrip()
            chanmodes = cont.get_info("modes")
            
            # Select the channels on which the script will publicly print the title
            # by replacing firstchannel, secondchannel, third channel etc.
            # you can also delete them or add them but you have to maintain the same syntax
            # do not delete quotes ( ' ' )
            if chan == '#firstchannel' or chan == '#secondchannel' or chan == '#thirdchannel':
                # PRINT IN CHANNEL
                # WARNING: In case two or more people in the same channel are using this script,
		# deleting or commenting the line with URL in it is strongly suggested
                # (could lead to endless chain-reactions otherwise)
                #
                # If channel has colors disabled
                if "c" in chanmodes:
                    msg = u":: {0} " + \
                          u":: URL: {1} " + \
                          u"::"     
                # If channel has colors enabled
                else:
                    msg = u"\002::\002\0034 {0} \003" + \
	                  u"\002:: URL: \002\00318\037{1}\017 " + \
                          u"\002::\002"
                msg = msg.format(title, url, nick, mode)
                # Weird context and timing issues with threading, hence:
                cont.command("TIMER 0.1 DOAT {0} MSG {0} {1}".format(chan, msg))
            else:
                # PRINT LOCALLY
                msg = u"\n" + \
                       u"\0033\002::\003 TITLE:\002\0034 {0} \003\n" + \
                       u"\0033\002::\003 URL: \002\00318\037{1}\017\n" + \
                       u"\0033\002::\003 POSTED BY:\002 {3}{2} \017\n" + \
                       u"\n"
                msg = msg.format(title, url, nick, mode)
                # Weird context and timing issues with threading, hence:
                cont.command("TIMER 0.1 DOAT {0} ECHO {1}".format(chan, msg))
    except requests.exceptions.RequestException as e:
        print(e)