<commit_before>from hamper.interfaces import ChatCommandPlugin, Command

try:
    # Python 2
    import HTMLParser
    html = HTMLParser.HTMLParser()
except ImportError:
    # Python 3
    import html.parser
    html = html.parser.HTMLParser()


import re
import requests
import json


class Lookup(ChatCommandPlugin):
    name = 'lookup'
    priority = 2

    short_desc = 'lookup <something> - look something up'
    long_desc = ('lookup and cite <something> - look something up and cite a '
                 'source\n')

    def setup(self, loader):
        self.search_url = "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q={query}&sl=en&tl=en&restrict=pr%2Cde&client=te"  # noqa
        super(Lookup, self).setup(loader)

    class Lookup(Command):
        ''' '''
        name = 'lookup'
        regex = '^(lookup\s+and\s+cite|lookup)\s*(\d+)?\s+(.*)'

        def command(self, bot, comm, groups):
            lookup_type = groups[0]
            def_num = int(groups[1]) if groups[1] else 1
            query = groups[2]

            resp = requests.get(self.plugin.search_url.format(query=query))
            if resp.status_code != 200:
                raise Exception(
                    "Lookup Error: A non 200 status code was returned"
                )

            # get rid of google cruft
            gr = resp.content.strip('dict_api.callbacks.id100(')
            gr = gr.strip(',200,null)')

            gr = gr.replace('\\x', "\u00")  # Google uses javascript JSON crap
            gr = json.loads(gr)

            if 'primaries' in gr:
                entries = gr['primaries'][0]['entries']
            elif 'webDefinitions' in gr:
                entries = gr['webDefinitions'][0]['entries']
            else:<commit_msg>addressed PR comments<commit_after>from hamper.interfaces import ChatCommandPlugin, Command

try:
    # Python 2
    import HTMLParser
    html = HTMLParser.HTMLParser()
except ImportError:
    # Python 3
    import html.parser
    html = html.parser.HTMLParser()

import re
import requests
import json


class Lookup(ChatCommandPlugin):
    name = 'lookup'
    priority = 2

    short_desc = 'lookup <something> - look something up'
    long_desc = ('lookup and cite <something> - look something up and cite a '
                 'source\n')

    search_url = "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q={query}&sl=en&tl=en&restrict=pr%2Cde&client=te"  # noqa

    def setup(self, loader):
        super(Lookup, self).setup(loader)

    class Lookup(Command):
        name = 'lookup'
        regex = '^(lookup\s+and\s+cite|lookup)\s*(\d+)?\s+(.*)'

        def command(self, bot, comm, groups):
            lookup_type = groups[0]
            def_num = int(groups[1]) if groups[1] else 1
            query = groups[2]

            resp = requests.get(self.plugin.search_url.format(query=query))
            if resp.status_code != 200:
                raise Exception(
                    "Lookup Error: A non 200 status code was returned"
                )

            # get rid of google cruft
            gr = resp.content.strip('dict_api.callbacks.id100(')
            gr = gr.strip(',200,null)')

            gr = gr.replace('\\x', "\u00")  # Google uses javascript JSON crap
            gr = json.loads(gr)

            if 'primaries' in gr:
                entries = gr['primaries'][0]['entries']
            elif 'webDefinitions' in gr:
                entries = gr['webDefinitions'][0]['entries']
            else:
{'fraction_non_alphanumeric': 0.12397163120567375, 'fraction_numerical': 0.015886524822695036, 'mean_word_length': 2.1594982078853047, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690182', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1023, 'n_words': 255}