Search for publications

def publications(columns, n_results, queries):
    """Search for publications"""
    if not isinstance(queries, dict):
        query_dict = {}
        for q in queries:
            key, value = q.split('=')
            if key == 'distinct':
                if value in ['True', 'true']:
                    query_dict.update({key: True})
                    continue
            try:
                value = int(value)
                query_dict.update({key: value})
            except BaseException:
                query_dict.update({key: '{0}'.format(value)})
    if 'sort' not in query_dict:
        query_dict.update({'order': '-year'})
    data = query.query(table='publications',
                       columns=columns,
                       n_results=n_results,
                       queries=query_dict)
    table = []
    headers = []
    for row in data['publications']['edges']:
        value = list(row['node'].values())
        for n, v in enumerate(value):
            if isinstance(v, str) and len(v) > 20:
                splited = v.split(' ')
                size = 0
                sentence = ''
                for word in splited:
                    if size < 20:
                        size += len(word)
                        sentence += ' ' + word
                    else:
                        sentence += '\n' + word
                        size = 0
                sentence += '\n'
                value[n] = sentence

        table += [value]

    headers = list(row['node'].keys())
    print(tabulate(table, headers, tablefmt="grid") + '\n')