<commit_before>import re

from util import hook, http


@hook.command
def calc(inp):
    '''.calc <term> -- returns Google Calculator result'''

    page = http.get('http://www.google.com/search', q=inp)

    # ugh, scraping HTML with regexes
    m = re.search(r'<h2 class=r style="font-size:138%"><b>(.*?)</b>', page)

    if m is None:
        return "could not calculate " + inp

    result = m.group(1).replace("<font size=-2> </font>", ",")
    result = result.replace(" &#215; 10<sup>", "E").replace("</sup>", "")
    result = result.replace("\xa0", ",")
    return result<commit_msg>update .calc to use lxml, fixes #44<commit_after>from util import hook, http


@hook.command
def calc(inp):
    '''.calc <term> -- returns Google Calculator result'''

    h = http.get_html('http://www.google.com/search', q=inp)

    m = h.xpath('//h2[@class="r"]/text()')

    if not m:
        return "could not calculate " + inp

    res = ' '.join(m[0].split())

    return res
{'fraction_non_alphanumeric': 0.19670442842430483, 'fraction_numerical': 0.016477857878475798, 'mean_word_length': 3.1186440677966103, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 1}, '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': '2308020', 'n_tokens_mistral': 351, 'n_tokens_neox': 329, 'n_words': 87}