<commit_before>from json import loads
from urllib import urlencode, quote

url = 'https://en.wikipedia.org/'

number_of_results = 10

def request(query, params):
    search_url = url + 'w/api.php?action=query&list=search&{query}&srprop=timestamp&format=json'
    params['url'] = search_url.format(query=urlencode({'srsearch': query}))
    return params


def response(resp):
    search_results = loads(resp.text)
    results = []
    res = search_results.get('query', {}).get('search', [])
    if not len(res):
        return results
    for result in res[:int(number_of_results)]:
        results.append({'url': url + 'wiki/' + quote(result['title'].replace(' ', '_').encode('utf-8')), 'title': result['title']})
    return results

<commit_msg>[enh] simplified mediawiki response processing<commit_after>from json import loads
from urllib import urlencode, quote

url = 'https://en.wikipedia.org/'

number_of_results = 10

def request(query, params):
    search_url = url + 'w/api.php?action=query&list=search&{query}&srprop=timestamp&format=json'
    params['url'] = search_url.format(query=urlencode({'srsearch': query}))
    return params


def response(resp):
    search_results = loads(resp.text)
    res = search_results.get('query', {}).get('search', [])
    return [{'url': url + 'wiki/' + quote(result['title'].replace(' ', '_').encode('utf-8')),
        'title': result['title']} for result in res[:int(number_of_results)]]

{'fraction_non_alphanumeric': 0.17409470752089137, 'fraction_numerical': 0.004178272980501393, 'mean_word_length': 4.794354838709677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '4409842', 'n_tokens_mistral': 461, 'n_tokens_neox': 452, 'n_words': 97}