<commit_before># -*- coding: utf-8 -*-
###
# Copyright (c) 2015, PrgmrBill
# All rights reserved.
#
#
###

import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircmsgs as ircmsgs
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import re
import requests
from urlparse import urlparse
from bs4 import BeautifulSoup
import random
import json
import cgi
import datetime
from jinja2 import Template
from urllib import urlencode
from datetime import timedelta
import timeout_decorator

try:
    from supybot.i18n import PluginInternationalization
    _ = PluginInternationalization("SpiffyTitles")
except ImportError:
    # Placeholder that allows to run the plugin on a bot
    # without the i18n module
    _ = lambda x: x

class SpiffyTitles(callbacks.Plugin):
    """Displays link titles when posted in a channel"""
    threaded = True
    callBefore = ["Web"]
    link_cache = []
    handlers = {}
    wall_clock_timeout = 8
    
    def __init__(self, irc):
        self.__parent = super(SpiffyTitles, self)
        self.__parent.__init__(irc)
        
        self.youtube_developer_key = self.registryValue("youtubeDeveloperKey")        
        self.wall_clock_timeout = self.registryValue("wallClockTimeoutInSeconds")
        
        youtube_handler_enabled = self.registryValue("youtubeHandlerEnabled")
        imgur_handler_enabled = self.registryValue("imgurHandlerEnabled")
        imdb_handler_enabled = self.registryValue("imdbHandlerEnabled")
        
        self.default_handler_enabled = self.registryValue("defaultHandlerEnabled")
        
        """
        Check if imgur client id or secret are set, and if so initialize
        imgur API client
        """
        imgur_client_id = self.registryValue("imgurClientID")
        imgur_client_secret = self.registryValue("imgurClientSecret")
        
        if imgur_handler_enabled and imgur_client_id and imgur_client_secret:
            self.log.info("SpiffyTitles: enabling imgur handler")
            
            # Images mostly
            self.handlers["i.imgur.com"] = self.handler_imgur_image
            
            # Albums, galleries, etc
            self.handlers["imgur.com"] = self.handler_imgur
            
            # Initialize API client
            try:
                from imgurpython import ImgurClient
                from imgurpython import ImgurClientError
                
                try:
                    self.imgur_client = client = ImgurClient(imgur_client_id, imgur_client_secret)                    
                except ImgurClientError as e:
                    self.log.error("SpiffyTitles: imgur client error: %s" % (e.error_message))                    
            except ImportError, e:
                self.log.error("SpiffyTitles ImportError: %s" % str(e))
        
        if youtube_handler_enabled and self.youtube_developer_key:
            self.log.info("SpiffyTitles: enabling youtube handler")
            
            self.add_youtube_handlers()
        
        if imdb_handler_enabled:
            self.add_imdb_handlers()
    
    def doPrivmsg(self, irc, msg):
        """
        Observe each channel message and look for links
        """
        channel = msg.args[0].lower()
        is_channel = irc.isChannel(channel)
        is_ctcp = ircmsgs.isCtcp(msg)        
        message = msg.args[1]
        now = datetime.datetime.now()
        title = None
        
        if is_channel and not is_ctcp:
            channel_is_allowed = self.is_channel_allowed(channel)            
            url = self.get_url_from_message(message)
            <commit_msg>SpiffyTitles: Fixes exception import for imgur client<commit_after># -*- coding: utf-8 -*-
###
# Copyright (c) 2015, PrgmrBill
# All rights reserved.
#
#
###

import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircmsgs as ircmsgs
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import re
import requests
from urlparse import urlparse
from bs4 import BeautifulSoup
import random
import json
import cgi
import datetime
from jinja2 import Template
from urllib import urlencode
from datetime import timedelta
import timeout_decorator

try:
    from supybot.i18n import PluginInternationalization
    _ = PluginInternationalization("SpiffyTitles")
except ImportError:
    # Placeholder that allows to run the plugin on a bot
    # without the i18n module
    _ = lambda x: x

class SpiffyTitles(callbacks.Plugin):
    """Displays link titles when posted in a channel"""
    threaded = True
    callBefore = ["Web"]
    link_cache = []
    handlers = {}
    wall_clock_timeout = 8
    
    def __init__(self, irc):
        self.__parent = super(SpiffyTitles, self)
        self.__parent.__init__(irc)
        
        self.youtube_developer_key = self.registryValue("youtubeDeveloperKey")        
        self.wall_clock_timeout = self.registryValue("wallClockTimeoutInSeconds")
        
        youtube_handler_enabled = self.registryValue("youtubeHandlerEnabled")
        imgur_handler_enabled = self.registryValue("imgurHandlerEnabled")
        imdb_handler_enabled = self.registryValue("imdbHandlerEnabled")
        
        self.default_handler_enabled = self.registryValue("defaultHandlerEnabled")
        
        """
        Check if imgur client id or secret are set, and if so initialize
        imgur API client
        """
        imgur_client_id = self.registryValue("imgurClientID")
        imgur_client_secret = self.registryValue("imgurClientSecret")
        
        if imgur_handler_enabled and imgur_client_id and imgur_client_secret:
            self.log.info("SpiffyTitles: enabling imgur handler")
            
            # Images mostly
            self.handlers["i.imgur.com"] = self.handler_imgur_image
            
            # Albums, galleries, etc
            self.handlers["imgur.com"] = self.handler_imgur
            
            # Initialize API client
            try:
                from imgurpython import ImgurClient
                from imgurpython.helpers.error import ImgurClientError
                
                try:
                    self.imgur_client = client = ImgurClient(imgur_client_id, imgur_client_secret)                    
                except ImgurClientError as e:
                    self.log.error("SpiffyTitles: imgur client error: %s" % (e.error_message))                    
            except ImportError as e:
                self.log.error("SpiffyTitles ImportError: %s" % str(e))
        
        if youtube_handler_enabled and self.youtube_developer_key:
            self.log.info("SpiffyTitles: enabling youtube handler")
            
            self.add_youtube_handlers()
        
        if imdb_handler_enabled:
            self.add_imdb_handlers()
    
    def doPrivmsg(self, irc, msg):
        """
        Observe each channel message and look for links
        """
        channel = msg.args[0].lower()
        is_channel = irc.isChannel(channel)
        is_ctcp = ircmsgs.isCtcp(msg)        
        message = msg.args[1]
        now = datetime.datetime.now()
        title = None
        
        if is_channel and not is_ctcp:
            channel_is_allowed = self.is_channel_allowed(channel)            
            url = self.get_url_from_message(message)
            
{'fraction_non_alphanumeric': 0.07171744405500134, 'fraction_numerical': 0.0037746023186842814, 'mean_word_length': 2.2568042142230027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1642083', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2025, 'n_words': 501}