<commit_before>import configs.module
import requests
import utils


def init():
    m = configs.module.Module(__name__)
    m.set_help('Get media recommendations from TasteKid (tastekid.com)')
    m.add_command_hook('suggest',
        {
            'help': 'A command to get recommendations from tastekid.com',
            'function': suggest,
            'args': [
                {
                    'name': 'results',
                    'help': 'Number of Results',
                    'optional':True,
                    'keyvalue':'number',
                    },
                {
                    'name': 'things you like',
                    'help': 'Things you like',
                    'optional': False,
                    'end': True,
                    },
                ]
            }
        )
    m.add_command_hook('setsuggestkey',
        {
            'help': 'Set the API Key for suggest.',
            'function': setkey,
            'args': [
                {
                    'name': 'key',
                    'help': 'API key',
                    'optional': True,
                    },
                ]
            }
        )
    return m


def setkey(fp, args):
    fp.server.db['suggest.apikey'] = args.getlinstr('key', '')
    return 'The key has been set to "%s"' % fp.server.db['suggest.apikey']


def suggest(fp, args):
    params = {'q': args.getlinstr('things you like'),
        'limit': 5, 'k':
            fp.server.db['suggest.apikey']
            if 'suggest.apikey' in fp.server.db else ''}
    if 'results' in args.lin:
        params['limit'] = args.getlinstr('results')
    if fp.ltnserver() and params['limit'] > 10:
        return "You cannot use this module from a server."
    suggestions = requests.get('http://www.tastekid.com/api/similar',
        params=params)
    suggestions = suggestions.json()["Similar"]
    if suggestions['Results'] == []:
        if params['limit'] <= 10:
            return fp.replypriv(
                'No results available; Please check your spelling')
        fp.replypriv('No results available; Please check your spelling')
        return
    likedmedia = {
        'book': [],
        'game': [],
        'music': [],
        'author': [],
        'movie': [],
        'show': [],
        }
    for i in suggestions['Info']:
        likedmedia[i['Type']].append(i['Name'])
    returnstring = "Because you liked the "
    for category in likedmedia:
        if not likedmedia[category] == []:
            if category == 'music':
                returnstring += 'music of ' + str(likedmedia[
                        category])[1:-1].replace("'", "") + ','
            else:
                returnstring += category + 's ' + str(likedmedia[
                        category])[1:-1].replace("'", "") + ','
    else:
        returnstring += ' TasteKid suggests '
    returnlist = []
    for i in suggestions['Results']:
        returnlist.append(i['Name'])
    returnstring += utils.ltos(returnlist)
    if params['limit'] <= 10:
        return returnstring
    fp.replypriv(returnstring)



<commit_msg>fix suggest<commit_after>import configs.module
import requests
import utils


def init():
    m = configs.module.Module(__name__)
    m.set_help('Get media recommendations from TasteKid (tastekid.com)')
    m.add_command_hook('suggest',
        {
            'help': 'A command to get recommendations from tastekid.com',
            'function': suggest,
            'args': [
                {
                    'name': 'results',
                    'help': 'Number of Results',
                    'optional':True,
                    'keyvalue':'number',
                    },
                {
                    'name': 'things you like',
                    'help': 'Things you like',
                    'optional': False,
                    'end': True,
                    },
                ]
            }
        )
    m.add_command_hook('setsuggestkey',
        {
            'help': 'Set the API Key for suggest.',
            'function': setkey,
            'args': [
                {
                    'name': 'key',
                    'help': 'API key',
                    'optional': True,
                    },
                ]
            }
        )
    return m


def setkey(fp, args):
    fp.server.db['suggest.apikey'] = args.getlinstr('key', '')
    return 'The key has been set to "%s"' % fp.server.db['suggest.apikey']


def suggest(fp, args):
    params = {'q': args.getlinstr('things you like'),
        'limit': 5, 'k':
            fp.server.db['suggest.apikey']
            if 'suggest.apikey' in fp.server.db else ''}
    if 'results' in args.lin:
        params['limit'] = args.getlinstr('results')
    if fp.ltnserver() and params['limit'] > 10:
        return "You cannot use this module from a server."
    suggestions = requests.get('http://www.tastekid.com/api/similar',
        params=params)
    suggestions = suggestions.json()["Similar"]
    if suggestions['Results'] == []:
        if params['limit'] <= 10:
            return fp.replypriv(
                'No results available; Please check your spelling')
        fp.replypriv('No results available; Please check your spelling')
        return
    likedmedia = {}
    for i in suggestions['Info']:
        if i['Type'] not in likedmedia:
            likedmedia[i['Type']] = []
        likedmedia[i['Type']].append(i['Name'])
    returnstring = "Recommendations from "
    for category in likedmedia:
        if not likedmedia[category] == []:
            returnstring += category + 's: ' + str(likedmedia[
                    category])[1:-1].replace("'", "") + ', '
        returnstring = returnstring.strip(', ') + '; '
    returnstring = returnstring.strip(',; ')
    returnstring += ' -- '
    returnlist = []
    for i in suggestions['Results']:
        returnlist.append(i['Name'])
    returnstring += utils.ltos(returnlist)
    if params['limit'] <= 10:
        return returnstring
    fp.replypriv(returnstring)




{'fraction_non_alphanumeric': 0.14169705004971828, 'fraction_numerical': 0.003314550878355983, 'mean_word_length': 1.6227727075184701, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1176446', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1617, 'n_words': 397}